判断ABAP代码是否处于update模式下运行的工具类

Posted sap-jerry

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了判断ABAP代码是否处于update模式下运行的工具类相关的知识,希望对你有一定的参考价值。

The class cl_system_transaction_state contains several useful utility methods:

  • get_in_update_task: return the flag whether current code is running with normal work process or in update work process

  • get_on_commit: return flag whether current code is called because of a previous registration via PERFORM ON COMMIT and triggered by COMMIT WORK

  • get_sap_luw_key: return current LUW ID
    I just use a very simple report to test them. First I call the FM ZSQF in a normal way, then call it via update task, then register it with PERFORM ON COMMIT and trigger it via COMMIT WORK.

WRITE: / ‘Direct call ZSQF begin...‘.

DATA(lv_luw_key) = cl_system_transaction_state=>get_sap_luw_key( ).

WRITE:/ ‘LUW key in main program:‘, lv_luw_key.

CALL FUNCTION ‘ZSQF‘.

WRITE: / ‘Direct call ZSQF end...‘.

CALL FUNCTION ‘ZSQF‘ IN UPDATE TASK.

PERFORM call_fm ON COMMIT.

COMMIT WORK AND WAIT.

lv_luw_key = cl_system_transaction_state=>get_sap_luw_key( ).

WRITE:/ ‘LUW key in main program after COMMIT WORK:‘, lv_luw_key.

FORM call_fm.

WRITE:/ ‘ZSQF is called on COMMIT begin...‘.

CALL FUNCTION ‘ZSQF‘.

WRITE:/ ‘ZSQF is called on COMMIT end...‘.

ENDFORM.

In the function module ZSQF, I just print out the three flags.

DATA(lv_in_update) = cl_system_transaction_state=>get_in_update_task( ).

DATA(lv_on_commit) = cl_system_transaction_state=>get_on_commit( ).

DATA(lv_luw_key) = cl_system_transaction_state=>get_sap_luw_key( ).

WRITE: / ‘Am I in update task? ‘ , lv_in_update.

WRITE: / ‘Am I triggered via PERFORM ON COMMIT?‘, lv_on_commit.

WRITE: / ‘Current LUW Key‘ , lv_luw_key.

The execution result shows the fact that the normal FM call, the FM registered to COMMIT WORK and the update task all run within the same LUW, and also proves the explanation of COMMIT WORK in ABAP help: “The COMMIT WORK statement closes the current SAP LUW and opens a new one”.

技术图片

The WRITE keyword executed in update task will not generate any output in SE38 list, and apart from switching on “update debugging” and check the three flags in debugger, there is also another way to log the content of the variable like lv_luw_key:
Just create a new checkpoint group via tcode SAAB, specify option “Log” for Logpoints and maximum validity period.

技术图片

Then append the following code in the FM implementation:

IF lv_in_update = 1.
   LOG-POINT ID ZUPDATELOG SUBKEY ‘Current LUW KEY‘ FIELDS lv_luw_key.
ENDIF.

Now after report execution, go to tcode SAAB, click Log tab, and we can find the content of lv_luw_key which is logged by the above ABAP code LOG-POINT ID ZUPDATELOG SUBKEY ‘Current LUW KEY’ FIELDS lv_luw_key.

技术图片

要获取更多Jerry的原创文章,请关注公众号"汪子熙":
技术图片




以上是关于判断ABAP代码是否处于update模式下运行的工具类的主要内容,如果未能解决你的问题,请参考以下文章

如何判断 C#程序是不是处于调试状态

如何检查系统是不是处于待机模式?

如何判断代码运行在DEBUG还是RELEASE模式下

如何开启 ABAP Update function module 和系统程序的调试功能

无法判断 Vue 项目是处于调试模式还是 Visual Studio 的发布模式

如何判断用户是不是处于IOS UIAccessibility的开关控制模式