如何获取ABAP程序执行的调用堆栈 [SYSTEM_CALLSTACK]

介绍一个有趣的函数SYSTEM_CALLSTACK(),这个函数可以得到abap程序执行的堆栈,包括事件(event),form。。。

例子代码如下:

REPORT ztest_stack.
DATA: num1 TYPE i,
      num2 TYPE i,
      sum  TYPE i.

num1 = 2. num2 = 4.
PERFORM frm_call.

*&---------------------------------------------------------------------*
*&      Form  frm_call
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM frm_call.
  sum = num1 + num2.
  PERFORM frm_output.
ENDFORM.                    "frm_call

*&---------------------------------------------------------------------*
*&      Form  frm_output
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM frm_output.
  FIELD-SYMBOLS: <fs> TYPE any.
  DATA: l_cstack_tab  TYPE sys_callst,
        ls_cstack_tab LIKE LINE OF l_cstack_tab.

  WRITE: / 'Sum of', num1, 'and', num2, 'is', sum.
  CALL FUNCTION 'SYSTEM_CALLSTACK'
    IMPORTING
      et_callstack = l_cstack_tab. " internal table
* l_cstack_tab 里就是abap的调用堆栈
  WRITE: sy-uline.
  LOOP AT l_cstack_tab INTO ls_cstack_tab.

    WRITE: / sy-tabix, ls_cstack_tab-eventtype,  ls_cstack_tab-eventname.

    CLEAR: ls_cstack_tab.
  ENDLOOP.

ENDFORM.                    "frm_output

执行结果,先触发事件 start-of-selection,然后调用frm_call,最后是frm_output.

2017-02-25_20-13-29

以上

posted @ 2019-08-30 16:37  真的是很难  阅读(1116)  评论(0编辑  收藏  举报