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 rollback issue

Former Member
0 Kudos

Hi,

I am elaborating my issue below.

1 ) I am using BAPI_PO_CREATE to create a po number.

2 ) Before use BAPI_TRANSACTION_COMMIT,

I am calling BAPI_GOODSMVT_CREATE to create material document, only by using the po number.

3 ) Once BAPI_GOODSMVT_CREATE is sucessfull then i am commiting both the bapi by BAPI_TRANSACTION_COMMIT.

4 ) But IF BAPI_GOODSMVT_CREATE is unsuccessful then i am calling BAPI_TRANSACTION_ROLLBACK for BAPI_PO_CREATE.

when i m checking by debug, its executing the BAPI_TRANSACTION_ROLLBACK,but the po is not removing / rollbacking from table like EKKO or EKPO table.

Please provide some suggestion, because if BAPI_GOODSMVT_CREATE is fails, i need to use BAPI_TRANSACTIOB_ROLLBACK  for both the above mentioned bapi.

Thanks & Regards,

Ajit sarangi

19 REPLIES 19

Former Member
0 Kudos

Hi

Do you mean you call one COMMIT only for both BAPIs?

Max

Former Member
0 Kudos

Dear,

yes, I used one Commit for both bapi, bcz if i m using bapi commit once then it ll work for all bapi.

Another think is that before COMMIT, the newly created po number has updated in tables, that i checked. (ekko and ekpo).

even i use separate commit for both bapi , still roll back is not working.

So please suggest, if BAPI_GOODSMVT_CREATE has fail , how to roll back BAPI_PO_CREATE ?

Thanks & REgards,

Ajit sarangi

0 Kudos

Uhm

but if you call the BAPI BAPI_PO_CREATE without the commit, how BAPI_GOODSMVT_CREATE can create an incoming goods for purchase order?

This order will exist only after calling the COMMIT

After creating the PO if BAPI_GOODSMVT_CREATE fails you should "delete" the PO

Max 

0 Kudos

Dear Ajit,

I had similar problem with 2 table updates.

Try using "SET UPDATE TASK LOCAL", this will solve problem like this.


Ex:


SET UPDATE TASK LOCAL.


Call BAPI1


if sy-subrc = 0.

  

   Call BAPI2.

   if Sy-subrc = 0.

     Commit.

   else.

     Rollback.

   endif.

endif.

0 Kudos

Dear Max,

My Bapi_goodsmvt_create is creating the material document without commit to bapi_po_create,bcz with the  po number created after bapi_po_create run and before bapi_po_create commit.

Then once bapi_goodsmvt_create is sucessfull, i m commiting both the bapi once by bapi_transaction_commit.

But whn 2nd bapi fails , i m not able to rollback the po number generated by first bapi execution.

plz help ????

Regards,

Ajit

0 Kudos

Dear Noorie,

Using SET UPDATE TASK lOCAL

also i m not able to roll back. can u plz expain abt set update task local clearly.

its urgent...

0 Kudos

Can you plz post your code.

0 Kudos

Dear Noorie,

As you suggest, I have done by below code...

SET UPDATE TASK LOCAL.


Call BAPI_PO_CREATE


if sy-subrc = 0.


(I am getting po number and also it updated in ekko and ekpo table)

 

   Call BAPI_GOODSMVT_CREATE


(Passing po number)


   if Sy-subrc = 0.


     Commit. for both bapi


   else.


     Rollback.


   perform error_mvt


   endif.


else.


perfor error_bapi_po.


endif.

0 Kudos

It is impossible to see EKKO entries before commit on Oracle DB. Maybe you did a commit in the debugger ?

0 Kudos

Hi Ajit,

0 Kudos

Dear Hans,

Yes i  m using sql- server,db- oracle

0 Kudos

If you use Oracle-Db and you can see EKKO and EKPO filled ins SE16 before commit, something is wrong. Maybe you have an user-exit where someone programmed a "commit work".

amitkumar24
Explorer
0 Kudos

Hi Ajit,

Try scenario of failed goods movement without debug. Use write something similar to know what PO was created. I think you'll find that ROLLBACK works.

-Regards,

Amit

0 Kudos

Dear,

I debugged and chked that po number created and update in table like ekko, ekpo.

but roll back is woking.

0 Kudos

Roll back will work within the LUW. Table entries also sometimes reverted whenever roll back calls.

Regards

Vadamalai A

0 Kudos

Hi Ajit,

I think your code logic is fine and it should behave the way you want. Does your logic works fine (rollback scenario & commit scenario both) when you do not debug it?

If it does, then I would put the blame on debugger. If SAP debugger is running in Non-exclusive mode then it'll do roll-in & roll-out for each step of code and hence commit is triggered at each step. So the PO creation done by your first BAPI call is committed even before you decide to commit or rollback.

Please let the community know if this explains things.

-Regards,

Amit

Former Member
0 Kudos

Dear hans,

Its not impossible, I am facing the problem,so that i am asking for suggestions from you guys...

Once bapi execute, without commit the po number is updated in tables.

0 Kudos

Dear Ajit,

that's why I was asking for your DB-System. If you use Microsoft SQL-Server you are right, if you you use Oracle you can not see anything without commit.

Go to any function module of function group XM06 and make a string search for "commit" in MAIN PROGRAM. Search bapi implementations for ME21N and do the same. There has to be reason why you can see EKKO and EKPO values before commit when using Oracle DB.

0 Kudos

Hi

I think Hans is right, there's something in your PO creation process raises a COMMIT, else:

- The data would not be saved in table (all saving processes start after COMMIT, so without commit no data in DB;

- The second BAPI would fail: I can't still understand how BAPI_GOODSMVT_CREATE can create a MM document for a PO if the PO doesn't exist (if you don't call the COMMIT after BAPI_PO_CREATE, you can have only the PO number, nothing else.

So something doesn't sound good

Try to check in the user-exit

Max