Subscribe

RSS Feed (xml)

Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger

Thursday, February 21, 2008

Using a variable from a calling program without passing it in parameter using abap

Did you ever try to use a variable from another program without passing this variable as a parameter. This is very useful when you CANNOT add the field as a standard parameter. For example, when you want to use a variable in a BADI which is not already passed as a parameter. Another good example is when you create a correction in a function and you want to keep the installation of the OSS note automatic (if you add parameters in a note, the user will have to install the note manually).

Here is a short example on how to do this :

REPORT zdany_test_var_from_fm.

TABLES: spfli.

DATA dbcnt TYPE sy-dbcnt.

DATA: itab TYPE spfli_tab.

SELECT * FROM spfli INTO TABLE itab UP TO 2 ROWS.

dbcnt = sy-dbcnt.

CALL FUNCTION 'ZFUNCTION'.

FUNCTION zfunction.

* We want to use the DBCNT from the program ZDANY_TEST_VAR_FROM_FM

DATA: field(50).

FIELD-SYMBOLS: .

field = '(ZDANY_TEST_VAR_FROM_FM)dbcnt'.

ASSIGN (field) TO .

WRITE .

* We want to use the internal table from the program ZDANY_TEST_VAR_FROM_FM

DATA: itab TYPE spfli.

FIELD-SYMBOLS: TYPE spfli_tab.

field = '(ZDANY_TEST_VAR_FROM_FM)ITAB[]'.

ASSIGN (field) TO .

LOOP AT INTO itab.

WRITE: / itab-carrid, itab-connid.

ENDLOOP.

ENDFUNCTION


Did you ever try to use a variable from another program without passing this variable as a parameter. This is very useful when you CANNOT add the field as a standard parameter. For example, when you want to use a variable in a BADI which is not already passed as a parameter. Another good example is when you create a correction in a function and you want to keep the installation of the OSS note automatic (if you add parameters in a note, the user will have to install the note manually).

Here is a short example on how to do this :

REPORT zdany_test_var_from_fm.

TABLES: spfli.

DATA dbcnt TYPE sy-dbcnt.

DATA: itab TYPE spfli_tab.

SELECT * FROM spfli INTO TABLE itab UP TO 2 ROWS.

dbcnt = sy-dbcnt.

CALL FUNCTION 'ZFUNCTION'.

FUNCTION zfunction.

* We want to use the DBCNT from the program ZDANY_TEST_VAR_FROM_FM

DATA: field(50).

FIELD-SYMBOLS: .

field = '(ZDANY_TEST_VAR_FROM_FM)dbcnt'.

ASSIGN (field) TO .

WRITE .

* We want to use the internal table from the program ZDANY_TEST_VAR_FROM_FM

DATA: itab TYPE spfli.

FIELD-SYMBOLS: TYPE spfli_tab.

field = '(ZDANY_TEST_VAR_FROM_FM)ITAB[]'.

ASSIGN (field) TO .

LOOP AT INTO itab.

WRITE: / itab-carrid, itab-connid.

ENDLOOP.

ENDFUNCTION

No comments:

Post a Comment

Content

Recent Topics