Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Where should we put 'BAPI_TRANSACTION_COMMIT' call in program?

Former Member
0 Likes
3,083

Hi all,

Need your expert opion/view on this, which one is more efficient, to put the 'BAPI_TRANSACTION_COMMIT' call right after bapi posting call in loop OR put the bapi commit call statement at the end of the process (after looping). This is one of the area in interface program that need can be improved to make the database update and table locking run efficiently. Let say there are 1000 documents (in loop) that need to be posted.

EXAMPLE:

Solution 1: To put commit right after bapi posting in loop:

loop at itab.

CALL 'BAPI_ACC_DOCUMENT_POST'

...............................................

CALL 'BAPI_TRANSACTION_COMMIT'

EXPORTING

WAIT = 'X'

endloop.

Solution 2: To put commit at end of process (after loop)

loop at itab.

CALL 'BAPI_ACC_DOCUMENT_POST'

...............................................

endloop.

CALL 'BAPI_TRANSACTION_COMMIT'

EXPORTING

WAIT = 'X'

Which one is more efficient and faster? solution 1 or 2?

Thanks all.

Edited by: Ahmad Ariza Abdullah on Oct 11, 2009 4:41 PM

6 REPLIES 6
Read only

Former Member
0 Likes
1,230

Hi,

Better solution is to put Commit FM inside the loop. IF document is succefully posted , call commit bapi otherwise call Rollback bapi. Aslo pass Wait parameter in BAPI.

Regards,

Rajneesh

Read only

former_member156446
Active Contributor
0 Likes
1,230

U need to commit only if the BAPI executed correctly without any errors...

loop at itab.

CALL 'BAPI_ACC_DOCUMENT_POST'
...............................................
if sy-subrc eq 0.
CALL 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'
endif.
endloop.

Read only

0 Likes
1,230

Thanks for all replies.

Let say there are 30000 documents have been posted via BAPI in program without immediate commit call in loop, where exactly SAP will store the updates details before the updates will be commited at the end of process? Can we check the details of each update? Appreciate if you can share documetation or your view on this.

How exactly SAP handle the BAPI call, request update(SM13) and commit statement?

Thanks in advance.

Read only

0 Likes
1,230

Hi Ahmad,

Every Bapi returns a message table i.e RETURN. If there is any error in execution of BAPI. This table will have an error message in it.

In your case, what you can do is to create one update function module, include BAPI_ACC_DOCUMENT_POST in this function module and update all the documents.

Now call your update function module with IN UPDATE TASK addtion, this way a LUW will be created.

Now call BAPI_TRANSACTION_COMMIT with import parameter WAIT = 'X'.

This way it will execute COMMIT WORK AND WAIT statement which returns a sy-subrc value.

If there is some error in your function module, you 'll get sy-subrc not equal to zero and no document will be updated.

Regards

Abhijeet

Read only

0 Likes
1,230

Unless and until you use a commit statement the BAPI will not commit, if the BAPI doesn't have auto commit in it.

Document number will be generated and it will be wasted, its better you commit after the successful bapi call.

Thanks,

Maehsh.

Read only

SujeetMishra
Active Contributor
0 Likes
1,230

Hello Ahmed,

Why are you passing single entry in loop ?

first you should take all entry in one internal table filter as per you requirement in Loop final table you pass in BAPI then use COMMIT , ROLLBACK. it will trigger your BAPI once

Regards,

Sujeet