Read Data From ABAP Stack

When implementing an enhancement, sometimes we need to read a field defined in the main program but which is not available in the enhancement point.

There is a technique which allows us the read the field if it is available in the ABAP stack.

Like for example (please refer to below screenshot), the field ‘TVAK-FPART’ is available in the main program ‘SAPMV45A’, however if the field is not available in the subroutine ‘VBAK_FUELLEN’ (program SAPFV45K) we can still access the field from the ABAP stack using the field symbol technique.

\"ABAP

 

Please find below a sample source code how to read data from the ABAP stack:

*Data Declarations:
*Constants.
CONSTANTS:
  lc_stack_loc(20)    TYPE c    VALUE \'(SAPMV45A)TVAK-FPART\'.

*Field Symbols.
FIELD-SYMBOLS:
  <fs_stackvalue>                TYPE ANY.

*If we have been able to read the required data
*from ABAP stack, proceed.
ASSIGN (lc_stack_loc) TO <fs_stackvalue>.

IF sy-subrc EQ 0
AND <fs_stackvalue> IS NOT INITIAL.

* Write the value read from ABAP stack.
  WRITE <fs_stackvalue>.

ENDIF.