Skip to Content
0

Get class/variable from ABAP Callstack

Oct 14, 2017 at 01:08 AM

95

avatar image
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Jacques Nomssi Oct 15, 2017 at 09:11 AM
0

You might be looking for the function module SYSTEM_CALLSTACK.

JNN

Share
10 |10000 characters needed characters left characters exceeded
Raymond Giuseppi
Oct 16, 2017 at 05:53 AM
0

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.

Share
10 |10000 characters needed characters left characters exceeded
Sandra Rossi Oct 16, 2017 at 07:48 AM
0

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>
Share
10 |10000 characters needed characters left characters exceeded