How to get the program call stack trace?

13,904

You may try SYSTEM_CALLSTACK.

DATA:
   abap_callstack_line TYPE abap_callstack_line,
   callstack TYPE  abap_callstack.


  CALL FUNCTION 'SYSTEM_CALLSTACK'
    EXPORTING
      max_level          = 4
    IMPORTING
      callstack          = callstack.

But in your case I would prefer an additional parameter and the calling place can fill this entry. I would not call the parameter called_by but something like behaviour or mode.

Share:
13,904
vlad-ardelean
Author by

vlad-ardelean

Currently: Python backends + some experimenting with react Previously: ABAP, Java EE, C# I'm just another physics major that ended up in programming. I m trying to be as sciency as I can about computer related stuff...sometimes it helps.

Updated on August 14, 2022

Comments

  • vlad-ardelean
    vlad-ardelean over 1 year

    My program can be started in 2 ways:

    the START OF SELECTION event that calls a MAIN function from one of my local classes. the ZAVGTTA4 transaction that calls the same method.

    at PAI, for the BACK event, when calling LEAVE TO SCREEN '0'., my program behaves in 2 ways according to how it was started. I want to get back to the selection screen (1000).

    I thought about querying the stack, where i'm sure to find how my program was called. I can see that the stack trace is different, but i don't know how to acces my stack from the program. I've heard about the RTTI that i think might be able to help me.

  • vlad-ardelean
    vlad-ardelean almost 12 years
    Thx. that did it. Btw, with your explanation, do you mean that some data object called "behavior" be declared in the 'DATA' section, and some piece of logic be implemented? Cuz that's what i did. But if you meand something different (and you think it's really nice to explain :P ) please provide some more details. Anyway thx alot!
  • knut
    knut almost 12 years
    I have some problems to give a correct example, because I did not really understand, how you call what. What are the two ways to call your programm? Via submit and with transaction ZAVGTTA4? The system field SY-TCODE contains the actual transaction. If SY-TCODE = 'ZAVGTTA4', then your programm is called with transaction ZAVGTTA4.
  • Jorg
    Jorg almost 12 years
    I know it's already answered but I'm wondering what the value of variable SY-CPROG is too (that's calling program name).
  • knut
    knut almost 12 years
    There is also SY-REPID - the program name. I have no SAP-System available, so I can't check it, but I think SY-REPID is the actual report (called by SA38 or direct per transaction). If you make make submits, SY-CPROG is the report "one level lower", SY-REPID is the first report.