Archive

Archive for the ‘ABAP’ Category

Lesson of the day

May 16th, 2010

Always use variable when trying to modify table, or else you’ll get randomly unexpected results.. well, at least that’s what happened to me with SAP/R3 4.6D.

For example, you’ve got a transparent table you wish to manipulate named: ZTXXX.
Create a variable named WA_ZTXXX.

DATA: WA_ZTXXX LIKE ZTXXX.

CLEAR WA_ZTXXX.
SELECT SINGLE * INTO WA_ZTXXX
FROM ZTXXX
WHERE [CONDITION].

IF SY-SUBRC EQ 0.
WA_ZTXXX-FIELD1 = ‘Blabla’.
WA_ZTXXX-FIELD2 = ‘Blibli’.

MODIFY ZTXXX FROM WA_ZTXXX.
ENDIF.

vera ABAP

Type conflict #1

July 14th, 2009

If you assign a field symbols with STANDARD TABLE type, you should never declare the reference with header line cause it will give you error.

WRONG:
DATA: ITAB LIKE BSID OCCURS 0 WITH HEADER LINE.
FIELD-SYMBOLS: <F> TYPE STANDARD TABLE.

It will give error when you do this:
ASSIGN (’ITAB’) TO <F> .

CORRECT:
DATA: ITAB LIKE BSID OCCURS 0.

vera ABAP , ,

User Exits

June 5th, 2009

I got the link from: http://www.sap-img.com/abap/a-short-tutorial-on-user-exits.htm

well, who knows I might need it later ;)

TITLE: A Short Tutorial on User Exits

Content Author: Abhishek

1. Introduction:

User exits (Function module exits) are exits developed by SAP. The exit is implementerd as a call to a functionmodule. The code for the function module is writeen by the developer. You are not writing the code directly in the function module, but in the include that is implemented in the function module.

The naming standard of function modules for functionmodule exits is:
EXIT_
<3 digit suffix>

The call to a functionmodule exit is implemented as:
CALL CUSTOMER.-FUNCTION <3 digit suffix>

Example:

The program for transaction VA01 Create salesorder is SAPMV45A Read more…

vera ABAP ,

Material beginning stock

March 19th, 2009

If you go through MB5B, you can see beginning stock, receiving / issuing, and ending stock of a specified material in specified plant / storage location. Now, if you need to get that beginning stock of a specified date, sometimes it becomes quite tricky.  I don’t know if SAP provides any function module to read that beginning stock.. I made several trials but never got a correct result that runs correctly for every material.  So, what I did was turning ST05 and run MB5B to see what it really does in the program. It turned out that the program actually “traceback” the stock from the current condition! It doesn’t read any history table (MARDH or MBEWH). I thought that method will take me forever to get the result, but I was wrong! It turned out to be the fastest way compared with all the other methods I tried by reading the history tables!

Here’s my code to get that beginning stock of a material:

Read more…

vera ABAP

Selecting MKPF-MSEG

March 11th, 2009

Selecting data from MKPF and MSEG can be quite tricky.. It will take forever to get just a few rows if you make the wrong selection.

Before you select anything from the table, you need to make sure your selections are in the table’s indexes and make as many conditions possible to restrict an exhaustive selection from the database.

I tried using select in select, get the mkpf in an internal table and then getting the mseg using for all entries, all took a long time… it just didn’t work the way I wanted to be.

And here’s my latest code as an example, and I’m satisfied with it.

Read more…

vera ABAP

Dynamic Internal Table

February 27th, 2009

REPORT YVERA_DYNAMICTABLE .

DATA: D_REF TYPE REF TO DATA,
D_REF2 TYPE REF TO DATA ,
I_ALV_CAT TYPE TABLE OF LVC_S_FCAT,
LS_ALV_CAT LIKE LINE OF I_ALV_CAT.

TYPES TABNAME LIKE DCOBJDEF-NAME .
PARAMETER: P_TABLEN TYPE TABNAME.

DATA: BEGIN OF ITAB OCCURS 0.
INCLUDE STRUCTURE DNTAB.
DATA: END OF ITAB.

FIELD-SYMBOLS : <F_FS> TYPE TABLE,
<F_FS1> TYPE TABLE,
<F_FS2> TYPE ANY,
<F_FS3> TYPE TABLE.

REFRESH ITAB.
CALL FUNCTION ‘NAMETAB_GET’
EXPORTING
LANGU          = SY-LANGU
TABNAME        = P_TABLEN
TABLES
NAMETAB        = ITAB
EXCEPTIONS
NO_TEXTS_FOUND = 1.
LOOP AT ITAB .
LS_ALV_CAT-FIELDNAME = ITAB-FIELDNAME.
LS_ALV_CAT-REF_TABLE = P_TABLEN.
LS_ALV_CAT-REF_FIELD = ITAB-FIELDNAME.
APPEND LS_ALV_CAT TO I_ALV_CAT.
ENDLOOP.
* internal table build
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING IT_FIELDCATALOG = I_ALV_CAT
IMPORTING EP_TABLE = D_REF .
ASSIGN D_REF->* TO <F_FS>.

SELECT * FROM (P_TABLEN) INTO CORRESPONDING FIELDS OF TABLE <F_FS>.

LOOP AT <F_FS> ASSIGNING <F_FS2>.
write:/ <f_fs2>.
*your code goes here.
ENDLOOP.

vera ABAP

Netweaver 7.01 ABAP Trial version

January 29th, 2009

Do you want to play with ABAP at home? Then try to download Netweaver 7.01 from this link:
https://www.sdn.sap.com/downloads/netweaver/abap/disclaimer.html

They also provide tutorial for installing this application. Here’s the link:
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/com.sap.km.cm.docs/library/elearning/abap/How%20to%20Install%20SAP%20NetWeaver%20Abap%207.0%20SP12%20-%20Trial%20Version/sim/description.htm

Enjoy!

vera ABAP ,

Conversion Exit

January 29th, 2009

If you notice, some fields in SAP tables have different values when you view them in SE16. For example, try to see table IFLO (functional location master) and input the functional location value. In my case, it’s UJ-UTI-GRL. Execute.

The displayed value is not UJ-UTI-GRL, but ‘?0100000000000000162′ instead. ‘UJ-UTI-GRL’ is the external value while ‘?0100000000000000162′ is internal value. When we access the table from the program, it only recognizes internal value. All wee need to do is do the conversion for the field using ‘CONVERSION_EXIT_TPLNR_INPUT’ to get the internal value and ‘CONVERSION_EXIT_TPLNR_OUTPUT’ vice verso.

Here’s the example code:
data: D_TPLNR TYPE TPLNR.
CALL FUNCTION ‘CONVERSION_EXIT_TPLNR_INPUT’
EXPORTING
input = viqmel-tplnr
IMPORTING
OUTPUT = D_TPLNR.

And voila! You’ll get your internal value for functional location stored in D_TPLNR variable.

You can also find other fields conversion exits. Go to SE37 and find other function module containing ‘CONVERSION_EXIT_XXX_INPUT’ where XXX is the field name.

Enjoy!

vera ABAP ,

Getting a field value of a screen field

January 29th, 2009

In dialog programming, the value of a screen field will be moved to the variable in your program after the Process After Input (PAI) is executed. What if you need the value before PAI is executed? For example, you have two fields in your screen: functional location (VIQMEL-TPLNR) and equipment (VIQMEL-EQUNR). You need to implement a search help for equipment number, but you only what to get equipments that is installed in the functional location specified.

When you debug your search help module, you can’t get the value of functional location the user entered. Why? Because your search help module will be placed in Process on value-request (POV), and the POV will be executed before PAI.

How to obtain your screen field value then? Simple. Just execute Function Module ‘GET_DYNP_VALUE’ and you will get what you want. Read more…

vera ABAP , ,

Multiple lines text element

January 27th, 2009

Did you ever need a multiple lines input for your user interface in dialog programming using screen painter? Well, I did. And I spent the whole day searching for a way to implement what I wanted.

Guess what! A few minutes ago I thought why didn’t I use an internal table with one element and put it in my screen? Why didn’t I think of that? Bummer! I had to waste a whole day searching for a “multiple lines text element” :P .

Here’s the code you will need to get what you want:

  1. First, you will need to declare an internal table containing 1 field only. For example:
    data: BEGIN OF T_LINES OCCURS 0,
    lines(100),
    END OF T_LINES.
  2. Read more…

vera ABAP , ,