Dirty Assign with ABAP

Using a dirty assign in ABAP will give you access to variables that are actually not e.g. part of an exporting parameter of a function module. See comment in the code. Magic happens in line 14 & 15, dependent on the value of variable field.

Like it? Share it!
REPORT zdirtyassign. TABLES: spfli. DATA lv_dbcnt TYPE sy-dbcnt. DATA: lt_tab TYPE spfli_tab. SELECT * FROM spfli INTO TABLE lt_tab UP TO 2 ROWS. lv_dbcnt = sy-dbcnt. CALL FUNCTION 'ZFUNCTION'. FUNCTION zfunction. * We want to use the DBCNT from the program ZSFLIGHTCOPY DATA: field(50). FIELD-SYMBOLS: <fs_dbcnt>. field = '(ZSFLIGHTCOPY)dbcnt'. "<< define the variable ASSIGN (field) TO <fs_dbcnt>. "<< this is the dirty part ;) WRITE <fs_dbcnt>. * We want to use the internal table from the program ZSFLIGHTCOPY DATA: lt_tab TYPE spfli. FIELD-SYMBOLS: <fs_lt_tab> TYPE spfli_tab. field = '(ZSFLIGHTCOPY)LT_TAB[]'. ASSIGN (field) TO <fs_lt_tab>. LOOP AT <fs_lt_tab> INTO lt_tab. WRITE: / lt_tab-carrid, lt_tab-connid. ENDLOOP. ENDFUNCTION

>_ Author Guest

>_ last updated 5 yearss ago

>_ Language: ABAP

Dirty Assign