0027 - Using a variable from a calling program.

Moderators: Snowy, thx4allthefish, Rich, ilya

Post Reply
Rich
Posts: 7116
Joined: Thu Oct 31, 2002 4:47 pm
Location: Liverpool
Contact:

0027 - Using a variable from a calling program.

Post by Rich » Sat Mar 28, 2009 8:39 am

Using a variable from a calling program without passing it in parameters.

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 :

Code: Select all

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: <dbcnt>.
field = '(ZDANY_TEST_VAR_FROM_FM)dbcnt'.
ASSIGN (field) TO <dbcnt>.
WRITE <dbcnt>.

* We want to use the internal table from the program ZDANY_TEST_VAR_FROM_FM
DATA: itab TYPE spfli.
FIELD-SYMBOLS: <itab> TYPE spfli_tab.
field = '(ZDANY_TEST_VAR_FROM_FM)ITAB[]'.
ASSIGN (field) TO <itab>.
LOOP AT <itab> INTO itab.
WRITE: / itab-carrid, itab-connid.
ENDLOOP.
ENDFUNCTION.
(Courtesy Dany Charbonneau)
Regards

Rich

Image
Abap KC:http://www.richard-harper.me.uk/Kb
SFMDR:http://www.se37.com

Post Reply