Application Development 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: 

BAPI _TRANSACTION_COMMIT AND ROLLBACK IN LOOP

srujanam
Explorer
1,565

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

GK817
Active Contributor
0 Kudos
718

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

GK817
Active Contributor
0 Kudos
719

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

Abinathsiva
Active Contributor
0 Kudos
718

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

former_member1716
Active Contributor
0 Kudos
718

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,