介绍一个有趣的函数SYSTEM_CALLSTACK(),这个函数可以得到abap程序执行的堆栈,包括事件(event),form。。。
例子代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
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.
以上。
发表评论