判断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的原创文章,请关注公众号"汪子熙":
- Hadoop运行wordcount时报classnotfound错误的一个原因
- 在WINDOWS下交叉编译LINUX程序运行不了是为什么?
- Hibernate的缓存机制
- error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http:/
- 【Go 语言 redis内存数据库存储 demo】
- linux下基本操作记录mongodb
- ClassLoader究竟为何物?
- Oracle应用实战八(完结)——存储过程、函数+对象曹组
- 动态代理模式原理
- SQL可以正常用,但cmd启动不了mysql,报错[ERROR] unknown variable ;basedir=....问题
- Percona-toolkit的安装和配置(r8笔记第86天)
- 分布式服务框架 Zookeeper
- python--类方法、对象方法、静态方法
- Go语言内存分配器的实现
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法