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_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给出的标准解释:
Here is what BAPI buffer is for: