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.
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