Skip to Content

Get class/variable from ABAP Callstack

Hi,

anybody know answer for below question?

https://archive.sap.com/discussions/thread/1365791

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Oct 15, 2017 at 09:11 AM

    You might be looking for the function module SYSTEM_CALLSTACK.

    JNN

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 16, 2017 at 05:53 AM

    From SYSTEM_CALLSTACK, you get the program name (even for class)

    But for class it's often easier to get a reference to the instance in another level of the stack and then access public attributes of this instance.

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 16, 2017 at 07:48 AM

    If it's a local variable, then you should add some custom code to the standard program or class, if possible, via the enhancement framework.

    Here is the shortest example if the program is a class pool.

    1. declare a public data reference :

    CLASS-DATA ref_to_localvariable TYPE REF TO <the type of localvariable>.

    Note that you may also need to make public the type of localvariable :

    TYPES zztype_localvariable TYPE <type of localvariable>.

    2. add an implicit enhancement at the beginning of the method:

    ASSIGN ('localvariable') TO <fs_to_localvariable>.
    IF sy-subrc = 0.
      GET REFERENCE OF <fs_to_localvariable> INTO ref_to_localvariable.
    ENDIF.

    3. Access the local variable from outside:

    FIELD-SYMBOLS <fs_ref_to_localvariable> TYPE classpool=>ref_to_localvariable.
    FIELD-SYMBOLS <fs_localvariable> TYPE classpool=>zztype_localvariable.
    ASSIGN ('(classpool===CP)ref_to_localvariable') TO <fs_ref_to_localvariable>.
    IF sy-subrc = 0 AND <fs_ref_to_localvariable> IS BOUND.
      ASSIGN <fs_ref_to_localvariable>->* TO <fs_localvariable>.
      " now work with the local variable by using <fs_localvariable>
    Add comment
    10|10000 characters needed characters exceeded