Application Development 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: 

cl_abap_get_call_stack (or the equivalent) - use at own risk or don't...?

Private_Member_7726
Active Contributor
0 Kudos

Hi,

I have a "twisted" requirement, which I cannot reject as unfeasible, and where I don't see a way to implement it without programming a wild "dependancy" on the context in which my logic will be called: "am I called in IS-U Print Document Display functionality call chain?". Does anyone know what is SAP's attitude towards using cl_abap_get_call_stack - i can't find a single use outside a testclass in ABAP 702, SAP ERP 605 System, but it does seem to function well. Has anyone experience using it? Has anyone a better alternative (looking at sy-cprog or sy-tcode will certainly not cut it).

Thank you,

Janis

1 ACCEPTED SOLUTION

former_member195402
Active Contributor
0 Kudos

Hi,

I'm not sure what you want but maybe this code will help you:

DATA: xt_ctm_rfc_call              TYPE  sys_callst. "Callstack Table

DATA: xs_ctm_rfc_call              TYPE  sys_calls.  "Callstack Line

  CLEAR                                  xt_ctm_rfc_call.

                                                                                                                                                                                                                                                              

  CALL FUNCTION 'SYSTEM_CALLSTACK'

    IMPORTING

      et_callstack                    =  xt_ctm_rfc_call.

                                                                                                                                                                                                                                                              

  LOOP                               AT  xt_ctm_rfc_call

                                   INTO  xs_ctm_rfc_call.

* do something

  ENDLOOP.

Regards,

Klaus

6 REPLIES 6

former_member186746
Active Contributor
0 Kudos

Hi,

You could try to filter down on the exact business requirement which led to this technical requirement.

It is indeed a bit strange and it is hard to see the added benefit to the business with this one.

Good luck!

Kind regards, Rob Dielemans

former_member195402
Active Contributor
0 Kudos

Hi,

I'm not sure what you want but maybe this code will help you:

DATA: xt_ctm_rfc_call              TYPE  sys_callst. "Callstack Table

DATA: xs_ctm_rfc_call              TYPE  sys_calls.  "Callstack Line

  CLEAR                                  xt_ctm_rfc_call.

                                                                                                                                                                                                                                                              

  CALL FUNCTION 'SYSTEM_CALLSTACK'

    IMPORTING

      et_callstack                    =  xt_ctm_rfc_call.

                                                                                                                                                                                                                                                              

  LOOP                               AT  xt_ctm_rfc_call

                                   INTO  xs_ctm_rfc_call.

* do something

  ENDLOOP.

Regards,

Klaus

raymond_giuseppi
Active Contributor
0 Kudos

This class is too young, but good old FM SYSTEM_CALLSTACK is somehow often used for test like 'called from BAPI' or such requirement.

Regards,

Raymond

ThomasZloch
Active Contributor
0 Kudos

I'm also hesitant about using the call stack and check for module names etc., since this logic might not survive the next major upgrade.

Two alternatives for finding out "where do I come from" could be:

  • setting a flag in global function group or class memory using an implicit enhancement "at the right place" (SET method or function module), that you can evaluate further down (GET method or function module)
  • grabbing and evaluating the value of a global variable from further up the call stack using the field symbol technique (OK, might also have a problem after the next upgrade...)

Thomas

0 Kudos

Yes, that would be my first choice too - enhance the SAP Functionality (FM) with my singleton that sets a flag on entry, check the flag down the call chain where I need to know. The trouble is - in this particular case, I absolutely must make sure my flag gets reset on leaving SAP FM and I can't "handle" exceptions of FM, can I..?

cheers

Janis

Private_Member_7726
Active Contributor
0 Kudos

You are right, of course, and I'm merely trying to deal somehow with consequences of wrong decisions on how a whole block of business requrements should (not) have been implemented. Unfortunately, I can't dream of "redoing it right" - that will be man-months of effort for no identifyable business of functional gain.

& Thank you, that FM looks much more encouraging.

cheers,

Jānis