Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Get class/variable from ABAP Callstack

3 REPLIES 3
Read only

nomssi
Active Contributor
0 Likes
4,291

You might be looking for the function module SYSTEM_CALLSTACK.

JNN

Read only

RaymondGiuseppi
Active Contributor
0 Likes
4,291

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.

Read only

Sandra_Rossi
Active Contributor
4,291

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>