<转>BAPI_TRANSACTION_COMMIT versus COMMIT WORK

转自:http://wiki.sdn.sap.com/wiki/display/ABAP/BAPI_TRANSACTION_COMMIT+versus+COMMIT+WORK
Many people continue using (or advising to use) COMMIT WORK after a call to a BAPI function module.

You must always call BAPI_TRANSACTION_COMMIT (not COMMIT WORK) if you have called at least one BAPI function module within the current LUW.

Here's why (inspired from this SDN thread):

By simply looking at BAPI_TRANSACTION_COMMIT code, we see quickly what is different from COMMIT WORK. It calls BUFFER_REFRESH_ALL function module right after COMMIT WORK.
So BAPI_TRANSACTION_COMMIT additionally refreshes a "BAPI buffer".
Here is what BAPI buffer is for:
Assuming your program calls BAPIs consecutively and use a COMMIT WORK/BAPI_TRANSACTION_COMMIT only at the end so that to commit all BAPI updates once (better performance).
As you know, BAPIs need to check errors like data missing in database. For example, the second BAPI may have to check the existence of data written by the previously called BAPI. The data doesn't exist in database yet, but as it knows it will be written later at COMMIT WORK time, it uses a buffer (memory) to store this information, so that no error is raised.
Let's suppose the update during the COMMIT WORK fails (for any reason), the data is not written to database. If you have not refreshed the buffer using BAPI_TRANSACTION_COMMIT, the next BAPI calls will consider that some data will exist later, that is wrong.
The same kind of logic applies to the rollback: you must call BAPI_TRANSACTION_ROLLBACK instead of ROLLBACK WORK. It will empty the BAPI buffer too. Here's why:

If you rollback the first BAPI using ROLLBACK WORK statement, you must absolutely refresh the buffer, otherwise the next BAPI could think that the data will exist and would attempt erroneously to write data.
All that is probably better explained in SAP Library documentation about BAPI buffer

To test a BAPI, you need to use a test sequence in SE37, for calling BAPI_TRANSACTION_COMMIT. See SDN wiki - Function Module Test Sequence.

For information:

SAP library documentation about BAPI template code shows why buffers were initially required at an older time: as only PERFORM ON COMMIT was available (CALL FUNCTION IN UPDATE TASK did not exist yet), all data had to be retained in memory (because the form is called once though registered several times).
Now, as only CALL FUNCTION IN UPDATE TASK should be used, it makes obsolete this documentation and the need for storing data in memory. But buffer is still in use as I explained above.
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值