After multiple calls to BAPI, the last COMMIT WORK will be any problem?

A friend asked me this question:

Call MIRO's BAPI, call it multiple times, and finally COMMIT WORK at one time, it can be executed successfully, but if it is called more than 100 times, and finally COMMIT WORK, will there be any problem?

I recommend reading these two articles first for some preliminaries:

Suppose a pseudo-code implementation of BAPI A is as follows:


* 进行一些计算,搜集出要插入数据库的记录,存在内表 lt_insert 中
* 进行一些计算,搜集出要更新数据库的记录,存在内表 lt_update 中
* 进行一些计算,搜集出要删除数据库的记录,存在内表 lt_delete 中

* BAPI 内部调用 XXX update function module,进行数据库更新操作
* 下面这个函数 XXX 仅当 COMMIT WORK 执行时,才会在另一个所谓的 update function module 里被触发调用

CALL FUNCTION 'XXX' IN UPDATE TASK
    EXPORTING
           it_insert = lt_insert
 it_update = lt_update
           it_delete = lt_delete

Code to call BAPI:

   CALL FUNCTION 'A'.

   COMMIT WORK.


So when the source code in our report is written as follows:

After the call to BAPI A on line 19, COMMIT WORKfollowed , the sequence of code blocks executed by the A, B, C, D runtime above is:

C -> A -> D -> B

That's right, although from the static source code, code block B is immediately after code block A, but at runtime B is executed after D, which is COMMIT WORK.

So calling BAPI multiple times and finally COMMIT WORK once, will there be a problem? This question cannot be generalized.

Assuming that the BAPI is called multiple times, the input parameters passed each time are the same, then:

  • In the safest case, if the BAPI only executes the database update operation each time, and the lt_update calculated by the code block A is exactly the same each time the BAPI is executed, then calling the BAPI multiple times and then executing the COMMIT WORK again will not work. side effect

  • If the BAPI is called repeatedly, the input is the same each time, but each time the lt_insert or lt_delete calculated by the code block A will generate a new record, then this means that after a COMMIT, there will be multiple 不同database insertion or deletion operations. . At this point, you must confirm that this multiple 不同database insertion or deletion operation is really the expected behavior?

In short, when calling the same BAPI multiple times, it is best to first find out whether there is a bug in the code writing, causing a BAPI to be called repeatedly, or is it intentional by the developer?

Guess you like

Origin blog.csdn.net/i042416/article/details/123562034