BAPI_TRANSACTION_COMMIT与COMMIT WORK区别

简要地看一下bapi_transaction_commit的代码,我们能很快看出其与commit work的区别。它会在执行commit work之后再调用一个buffer_refresh_all的函数

所以bapi_transaction_commit额外地刷新了BAPI buffer缓冲区。

下面是bapi buffer的用处:
1、假设你的程序连续地调用了若干个bapi,然后在最后使用了commit work/bapi_transaction_commit,这样会一次性提交所有bapi更新
2、众所周知,bapi调用会检查一些错误,如数据库中数据的存在与否.例如第二个bapi可能必须去检查前一个bapi所写的数据的存在与否。但此时数据还没写入到数据库中,要等到待会而commit work的时候才会被写入。这是就需要缓存来存储这些信息,以保证不会引发错误。
3、让我们设想因为某种原因更新commit work失败了,数据未能写入数据库。如果你没有没有使用bapi_transaction_commit刷新缓冲区,下一次bapi调用将认为这些缓存仍将存在,这样会导致错误。

同样的道理也可以推及到回滚:你必须使用bapi_transaction_rollback来代替rollback work。它也会清空缓存,原因如下:
如果你使用rollback work来回滚第一个bapi,你必须确保缓冲区被清空,否则下一个bapi会认为这些数据仍然存在并错误地去尝试写数据

所以我们在连续修改很多表,而这些表又相互关联,或者循环修改表,最好使用bapi_transaction_commit

下面是SAP给出的标准解释:

  • 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.

有些bapi后天执行不成功,但是debug 就可以成功,加 WAIT UP TO ** SECONDS.

 

  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值