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: 

COMMIT WORK in Badi

Former Member
0 Kudos

Hi Experts,

What exactly are the implications or advantages of placing a 'COMMIT WORK' statement in a Badi Implementation.

To be more specific, in one of the implementations of Order_Save Badi, I'm trying to update a custom table. At this point I'm using the 'Commit Work' statement .

Any inputs on this regard would be of great help.

Thanks in Advance,

Kris.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Commit work will end a LUW. and a new LUW will start fromm there..

ur Save Order is a combination of LUWs..

After the commit work statement is executed the custom table will get updated through Update work process. else... U records would not get update in DB..even though You insert/modify/change a record in table

Hope i have answered ur question..

Sarath

12 REPLIES 12

Former Member
0 Kudos

Commit work will end a LUW. and a new LUW will start fromm there..

ur Save Order is a combination of LUWs..

After the commit work statement is executed the custom table will get updated through Update work process. else... U records would not get update in DB..even though You insert/modify/change a record in table

Hope i have answered ur question..

Sarath

Former Member
0 Kudos

Hi,

To give you a very specific answer, the COMMIT WORK statement triggers following reactions.

1. SAP LUW ends

2. All Buffers are refreshed i.e cleared.

The implication can be that your code may go into dump or the data updated might be missed as in between the process you are clearing all buffer memories.

Hope its clear,

RJ

soumya_jose3
Active Contributor

Hi Kris,

COMMIT WORK should not be used in BADIs.

Commit work in BADI is dangerous as if you do a commit work in the BADI , it will commit the database changes. But after the BADI execution it finds that some data is not proper and so the transaction is terminated without saving or creating the record. But since the commit work was performed in the BADI, those unnecessary changes will be there in the database even though the transaction has not been saved.

You can do your changes in the BADI without commiting and later on when the transaction is completed, the std code will do a commit work . In that commit work your changes in the BADI will also be committed.

Regards,

Soumya.

0 Kudos

Thanks Soumya,

That is a helpful info.

But in my case, the database tables are not updated properly if I remove the COMMIT WOTK statement.

I tried debugging the implementation code where I'm inserting the data into the custom table from an internal table.

In the internal table, the data was proper. But after the debugger leaves the implementation, I press F8 and find that the custom table has one of the fields updated with twice the expected value.

Is there any otherway I can force a commit on to the database or eradicate this malfunctioning ?

Thanks in Advance,

Kris.

0 Kudos

Hi Kris,

There might be some bug in the code written in the BADI.

Can you paste the code by which you are updating the custom table here???

Regards,

Soumya.

0 Kudos

Hi Soumya,

This is the code that I've written within the Order_Save badi implementation.

*********************************************************************************

Select * from ZCUSTOM into table ITAB.

Read Table ITAB into WA_ITAB with key

WA_ITAB - Delivered_Quantity = WA_ITAB - Delivered_Quantity + Input_Delivered_quantity.

Modify table ITAB from WA_ITAB.

If NOT ITAB[] IS INITIAL.

MODIFY ZCUSTOM from ITAB.

endif.

*********************************************************************************

The delivered quantity was 25 initially.

Input_Delivered_quantity has the value 5.

I checked the internal table ITAB contents in the debugger before the last IF statement.

ITAB[2]-Delivered_Quantity has the value 30 as expected.

I checked the database table after the modify statement. It was not updated.

After the next COMMIT WORK statement, the database table has been updated, but with the value 35 instead of 30.

This is not always the same. Some times I observe a proper value in the database table, but sometimes double the expected value....

Is there anything that could be done to avoid this issue ?

Regards,

Kris.

0 Kudos

Hi Kris,

I believe the COMMIT WORK you are referring to is not in the BADI implementation and it is in the std code.

Since after the modify statement in the BADI implementation, the value is 30, you must check at any other point this table ZCUSTOM is getting updated in any other BADI implementation methods or in any other methods of the same implementation. You can check this while debugging.

Regards,

Soumya.

0 Kudos

May be the same code is executed twice.Did u chk that?

Try this

if flag NE 'X'.
Select * from ZCUSTOM into table ITAB.

Read Table ITAB into WA_ITAB with key 
WA_ITAB - Delivered_Quantity = WA_ITAB - Delivered_Quantity + Input_Delivered_quantity.

Modify table ITAB from WA_ITAB.

If NOT ITAB[] IS INITIAL.
MODIFY ZCUSTOM from ITAB.
flag = 'X'.
endif.
endif.

Rhea.

0 Kudos

Hi Soumya and Rhea,

I checked if any other implementation/method of this badi is updating the custom table.

But none.

Also, I checked if the code is executed twice.

I placed a break point above the MODIFY statement. If this statement is executed twice, the debugger must stop at the same point for the second time as well, but it didn't.

I tried the following update function module so that the function module will be triggered at the next commit work.

*******************************************************************************************

CALL FUNCTION 'ZISD_SAVE_CUSTOM_INVENTORY' IN UPDATE TASK

TABLES

IT_INPUT = ITAB.

*******************************************************************************************

But this time, the function module is not triggered at the COMMIT WORK statement.

Is there anything else that needs to be done for this function module to be triggered at the COMMIT WORK statement ?

Regards,

Kris.

Former Member
0 Kudos

Just check if your Read statement or the Modify statement is not failing in some cases.

0 Kudos

Hi Thomas,

I checked the modify statement.

When the statement fails, it is either giving a SY-SUBRC <> 0 or a short dump.

But in my case, the value of a column is updated with twice the value.

Any alternative ?

Regards,

Kris.

Former Member
0 Kudos

Closed.