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

Commit work

Former Member
0 Likes
1,564

Hi All,

I am callinf a Z FM from an User exit . If i do a Commit Work inside the FM does it release all the data base locks set by the standard transaction ? I was worried that the data base may be updated by that commit work inside my FM. How does this work? Please share your views.

14 REPLIES 14
Read only

Former Member
0 Likes
1,379

Hi harikrishnan balan,

Yes, if you do a COMMIT WORK inside your userexit you will potentially cause data to be updated and ENQUEUE locks to be freed.

Much better, is to perform your updates by calling a another Z function module which performs the actual SQL INSERT/UPDATE/DELETE statements in UPDATE TASK (you will need to change the function module attributes to do this).

Then, if SAP decides that is going to do updates it will issue a COMMIT WORK and your function (and all the standard ones) will be executed together in the update task.

The only potential problem with this approach, is that if you need to perform updates and SAP doesn't detect any changes. Normally you can overcome this by adding an extra field to one of the SAP tables (as an append structure) and always changing the value of this in your userexit (by changing the corresponding global data field) whenever you need to make sure SAP issues a COMMIT WORK.

So, the short answer is: DONT ISSUE A COMMIT WORK IN YOUR USEREXITS!!!!!!

Hope that helps.

Brad

Read only

0 Likes
1,379

Hi Brad,

Thanks for the reply. I am actually trying to use the FM SO_OBJECT_SEND in my FM to send mails to external id. From 4.7 the mail send FM does not work unless i explicitly do a commit work. So the scenario is like this-In user exit i call a Z FM which calls SO_OBJECT_SEND.But to get this to work i need to do a commit work.Is there any other solution to this issue?

Regards,

Hari.

Read only

0 Likes
1,379

Hi Hari,

Which SAP transaction and which userexit?

Brad

Read only

0 Likes
1,379

Hi Brad,

It is for VA01,02 transactions user exit USEREXIT_SAVE_DOCUMENT in include MV45AFZZ. Can i do a call function on commit so that my FM gets called after SAP does a commit work and it will be safe to do a database commit after that?

Regards,

Hari.

Read only

0 Likes
1,379

Hi Hari,

You could do this using a PERFORM ... ON COMMIT.

But it should work just by having the call to SO_OBJECT_SEND in the USEREXIT_SAVE_DOCUMENT.

This is because SAP will issue a COMMIT WORK in its own save logic.

Does this not work?

Brad

Read only

0 Likes
1,379

Hi Brad,

No , this is not working. The mails are not getting sent. That is why i was wondering if i will do a call function on commit and then do an Explicit commit work in my Z FM.

Regards,

Hari.

Read only

0 Likes
1,379

Hi Hari,

There is no such thing as call function on commit. There is call function in update task and there is perform on commit.

BUT, neither of these two options allow you to perform your own COMMIT WORK inside them. This will cause an error.

Can you try a test for me?

Leave your code without a COMMIT WORK in it, and the function call to send the email in USEREXIT_SAVE_DOCUMENT. Then change a document in VA02 by changing a quantity or a text, something that will force SAP to issue a COMMIT WORK to make the changes update on the database, then hit save.

If that works, then I have a method for making sure it works even if the user doesn't change anything and hits save (if you need to).

If it doesn't there is something else to try...

Let me know.

Thanks,

Brad

Message was edited by: Brad Williams

Read only

Former Member
0 Likes
1,379

Hello hari,

the user-exit form USEREXIT_SAVE_DOCUMENT is called before commit work.

You want to try commit work then use USEREXIT_REFRESH_DOCUMENT.

Regards,

Samir.

Read only

0 Likes
1,379

Hi Samir,

If i am using call function on commit does the place where i call the FM make a difference? Wont my FM be executed once SAP does a data base commit in the standard code? And i think after that i may safely use a commit statement in my code. Please correct me if i am wrong.

Regards,

Hari.

Read only

Former Member
0 Likes
1,379

Hi Hari,

Looks like you want to send an email out to someone upon saving the sales order.

Why don't you try the output determination mechanism instead of user exit? It will pretty standard and easy doing it in config rather than trying it this way.

Srinivas

Read only

0 Likes
1,379

Hi Srini,

The mail has to be sent when some one changes the sold to for the order to notify the change. So we cant use output determination.

Regards,

Hari.

Read only

0 Likes
1,379

Hi Hari,

Both Samir and Srinivas raise good points.

But first, again there is no CALL TRANSACTION on COMMIT. And, with PERFORM ... ON COMMIT you cannot issue another COMMIT WORK, its not allowed!!!!

Samir's suggestion of putting it at USEREXIT_REFRESH_DOCUMENT would work. You could then issue your own COMMIT WORK in this. This is probably the simplest solution.

Srivivas's suggestion would also work. You just need to do two things. Make the output type 'Multiple Issuing' in SPRO and put a requirement (coded in VOFM) against it checking that the sold-to party has been changed. This would take a little more work.

It still puzzles me why it would not work in USEREXIT_SAVE_DOCUMENT, but short of doing the coding myself and getting it to work I would recommend doing it in USEREXIT_REFRESH_DOCUMENT.

Cheers,

Brad

Read only

0 Likes
1,379

Hi All,

Thanks for your replies. We have nailed the problem. Actually it was something else. SO_OBJECT_SEND has a parameter ORIGINATOR where we can pass the sender ID. This was being populated from a table that was not maintained properly and although the sy-subrc was 0 after the function call , due to a junk value in this parameter the mails were not being sent. Thanks again for all the responses.From 4.7 commit work have to be added after call to this FM. But as it being done in the standard code we do not have to code for this.

Regards,

Hari.

Read only

0 Likes
1,379

Hi Hari,

So I wasn't going crazy after all...

Glad to see that you got it going.

Can you please close off the thread.

Cheers,

Brad