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

Former Member
0 Likes
4,580

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
Read only

Former Member
0 Likes
3,079

Hi

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

Max

Read only

Former Member
0 Likes
3,079

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

Read only

0 Likes
3,079

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 

Read only

0 Likes
3,079

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.

Read only

0 Likes
3,079

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

Read only

0 Likes
3,079

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...

Read only

0 Likes
3,079

Can you plz post your code.

Read only

0 Likes
3,079

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.

Read only

0 Likes
3,079

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

Read only

Former Member
0 Likes
3,079

Hi Ajit,

Read only

0 Likes
3,079

Dear Hans,

Yes i  m using sql- server,db- oracle

Read only

0 Likes
3,079

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".

Read only

amitkumar24
Explorer
0 Likes
3,079

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

Read only

0 Likes
3,079

Dear,

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

but roll back is woking.

Read only

0 Likes
3,079

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

Regards

Vadamalai A

Read only

0 Likes
3,079

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

Read only

Former Member
0 Likes
3,079

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.

Read only

0 Likes
3,079

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.

Read only

0 Likes
3,079

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