A friend asked me this question:
Call Miro’s Bapi for many times and commit work at the last time. It can be executed successfully, but if you call Miro’s Bapi more than 100 times and commit work at the last time, what will be the problem?
I suggest reading these two articles first to learn some preliminary knowledge:
Suppose a pseudo code of Bapi A is implemented as follows:
*Perform some calculations to collect the records to be inserted into the database and store them in the internal table Lt_ In insert *Perform some calculations to collect the records to be updated in the database and store them in the internal table Lt_ In update *Perform some calculations to collect the records to be deleted from the database and store them in the internal table Lt_ Deleting *Bapi calls XXX update function module internally to update the database *The following function XXX will be triggered and called in another so-called update function module only when commit work is executed CALL FUNCTION 'XXX' IN UPDATE TASK EXPORTING it_insert = lt_insert it_update = lt_update it_delete = lt_delete
Code calling Bapi:
CALL FUNCTION 'A'. COMMIT WORK.
So when the source code in our report is written as follows:
Bapi A is called on line 19 and then on line 21
COMMIT WORKThen, the sequence of code blocks executed during the above a, B, C and D runs is:
C -> A -> D -> B
Yes, although from the static source code, code block B is immediately after code block a, runtime B executes after D, i.e. commit work.
So is there a problem when Bapi is called many times and the last one-time commit work? This problem cannot be generalized.
Assuming that Bapi is called many times and the input parameters passed each time are the same, then:
- In the safest case, if the Bapi only performs database update every time, and the LT calculated by code block a every time the Bapi executes_ The updates are completely consistent. If Bapi is called many times, and then commit work is executed again, there will be no side effect
- If the Bapi is called repeatedly, the input is the same every time, but the LT calculated by code block a every time_ Insert or LT_ Delete will generate new records, which means that multiple records will be generated after one commit
DifferentInsert or delete the database. At this time, it must be confirmed that this situation is repeated
DifferentIs the expected database insertion or deletion really?
In short, if you call the same Bapi many times, you’d better find out first. Is it a bug in the code writing that causes a Bapi to be called repeatedly, or is it the developer’s intention?