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: 

How to COMMIT within a User-exit or BADI

Former Member
0 Kudos

HI Gurus,

Scenario:

User-exit called from SAP transaction.

It needs to update Z*table and then do standard Sap processing.

Whats it doing:

However when I run it, I realise that it is not updating the Z*table.

I tried to introduce a wait statement and then sometimes it does commit data to Z*table and sometimes it doesnt.(NO error returned. Sy-subrc = 0. However if I use a COMMIT statement, the program gives runtime error.

What I need:

Is there a way how I can make sure that data is written to Z* table first and only then is the stanadrd SAP processing done. (as mentioned writing a COMMIT staement is not helping...so how do I commit data to Z*table before going ahead in same transaction? )

Appreciate your response on same.

Many thanks

Shirin

7 REPLIES 7

former_member156446
Active Contributor
0 Kudos

Hi

if the Ztable needs to be updated you will be using Modify , Insert statments... the structure of the work area and Ztable need to be same.

0 Kudos

Hi Jay,

i guess you did not get my question. Let me give some more details

I am using an UPDATE statement withing the exit. (work area structure is same as that of z*table).

Update statement executes fine (sy-subrc = 0).

Once this is done, I let SAP continue with standard processing. When I check the results, SAP standard processing has worked fine but Z*table is not updated. So I introduced WAIT statement after my UPDATE statem,ent and it works fine if the no of records is upto 10.

Anything after 10 records, the results are not predictable. In some cases it updates and sometimes doesnt.

( I read some threads and they talk about COMMIT statement. However I can not use that with the user-exit...it errors).

So I am trying to find a way, how to make sure that Z*table is updated and then only stnadrd SAP processing resumes.

Regards

Shirin

0 Kudos

did you try increasing the wait time..

commit work and wait X seconds. X?

0 Kudos

Write your update code in a function module and call the function module in STARTING A NEW TASK mode and within function module give commit work.

Former Member
0 Kudos

Hi,

You probably have you write a function module (remote enable it ) that updates the Z table and then call that function module with destination 'NONE'. (write a commit work after the z table update )

I'm not sure if this would work but the documentation says

Note that a database commit occurs at each Remote Function Call (RFC). Consequently, you cannot use Remote Function Calls between pairs of statements that open and close a database cursor (such as SELECT ... ENDSELECT).

regards,

Advait

ThomasZloch
Active Contributor
0 Kudos

For updating Z-tables in user exits I usually call a subroutine with PERFORM ... ON COMMIT. This way your code is being executed once the standard transaction sends a COMMIT WORK. This will update the Z-table immediatly after the standard tables.

I don't think it is possible to have the Z-table updated before the standard tables though. What would be a reason that this might be mandatory?

Never invoke a COMMIT WORK directly in your user exit.

Thomas

0 Kudos

hi thomas,

can youplease let explain why we should not call commit inside badi ?

ex : inside badi impl:

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.

commit work.

endif.

can we use this or please tell the alternate for this .