Read CALL STACK to check on called Program

By | Last Updated on April 9, 2013 | 45,809

FM SYSTEM_CALLSTACK comes in handy when it is needed to check on the called program which is calling the current code block. This FM can be called in any code module – Methods, FMs, Subroutines, etc.

Read CALL STACK to check on Called Program

 
DATA: t_abap_stack TYPE  abap_callstack,
      t_sys_stack  TYPE  sys_callst.
 
START-OF-SELECTION.
" FM To get the Call Stack information when running the program
" ABAP Callstack would give you the Program names
" SYS callstack would give you system programs in callstack
*
  CALL FUNCTION 'SYSTEM_CALLSTACK'
*  EXPORTING
*    MAX_LEVEL          = 0
   IMPORTING
     callstack          = t_abap_stack
     et_callstack       = t_sys_stack.
*
  READ TABLE t_abap_stack TRANSPORTING NO FIELDS
    WITH KEY mainprogram = 'ZTEST_NP'.   "Your Program name
  IF sy-subrc NE 0.
    "Not found, go away
    EXIT.
  ELSE.
    "Continue the journey
  ENDIF.
 

UPDATE

This FM will only bring the current Call Stack. So, whenever a new LUW is introduced using NEW TASK, Background Task, Update Task, RFC, SUBMIT, CALL TRANSACTION; this FM would only bring the current Program in Call Stack. This would match exactly what you see in Debugger’s call stack.

Do you have a Code Snippet which you want to share, Submit Code Snippet here

Tags

Share It!

Don't miss an Update

Get notified of the new post, right into your inbox

Naimesh Patel{274 articles}

I'm SAP ABAP Consultant for more than a decade. I like to experiment with ABAP especially OO. I have been SDN Top Contributor.
Follow :

Explore all of his 274 articles.

Load comments

4 Comments

  • Varun Kumar Sahu

    Pretty handy yet powerful check! Thanks a lot sharing. Well now I have a validation check on SUBMIT programs.

  • Nice!

    Like the new code snippet section! Keep up the great blog Naimesh!

  • Hello Varun,

    This FM wont work in SUBMIT programs. Whenever system starts a New LUW (a new Task, SUBMIT, RFC), this FM wont work as there is no active call stack for that LUW.

    Thanks,
    Naimesh Patel

  • Wouter

    Very useful. Naimesh, a request for a code snippet: how to easily build up a table of unique keys?
    For example you got an internal table with 100’s of lines but one column will only contain 3 unique keys.

    I mostly create a local table type, loop and add, afterwords just sort and delete adjacent.

    Regards,
    Wouter

Comments on this Post are now closed. If you have something important to share, you can always contact me.