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

BAPI _TRANSACTION_COMMIT AND ROLLBACK IN LOOP

srujanam
Explorer
2,966

Hi,

In the logic that I built, I have to loop , and for each item

1. Goods Issue(GI) using BAPI_GOODSMOVEMENT_CREATE, and if successful commit it.

2. If GI created create Transfer requirement(TR) for GI. Commit if successful. (Question)

3. If TR is created, create Transfer Order for TR. If error (Question).

Question: If there is error creating TR , I would have to reverse the Goods movement which would create another MIGO document. So if I use BAPI_TRANSACTION_ROLLBACK, will it reverse all the previous created/commited GI/TR/TO as all these are in the same LUW?

1 ACCEPTED SOLUTION
Read only

GK817
Active Contributor
0 Likes
2,119

Hi,

No,BAPI_TRANSACTION_ROLLBACK will not reverse previous commits.

You should use BAPIs in first 2 steps to know if there are any errors. Based on that, call BAPI_TRANSACTION_COMMIT at the end of third step. Then all the 3 steps will be in one LUW and that's how it should be done.

Regards

GK

3 REPLIES 3
Read only

GK817
Active Contributor
0 Likes
2,120

Hi,

No,BAPI_TRANSACTION_ROLLBACK will not reverse previous commits.

You should use BAPIs in first 2 steps to know if there are any errors. Based on that, call BAPI_TRANSACTION_COMMIT at the end of third step. Then all the 3 steps will be in one LUW and that's how it should be done.

Regards

GK

Read only

Abinathsiva
Active Contributor
0 Likes
2,119

Hi Srujana Reddy

check out the errors after BAPI_GOODSMOVEMENT_CREATE by filtering Return bapi Internal table for Errors.. if error don't commit the results.

Regards,

Abinath

Read only

former_member1716
Active Contributor
0 Likes
2,119

The Logic is simple:

All the transactions that are committed Cannot be Rolled back. In Your Case you are trying to roll back transactions that are committed already which is not possible and correct too.

Probably you can alter your Logic as below:

1) Do not commit any transactions until your complete Cycle is completed successfully.

2) In case if there is failure at any step of the cycle then you Roll back (Without committing any transaction up front), this could be favorable for your scenario.

Regards,