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: 

Error while triggering program through output type while saving invoice

Former Member
0 Kudos

Hi,

I have a scenario where in my Z program needs to be triggered when saving a invoice.

For that we have attached out Z program to output type which gets picked while saving invoice.

In the Z program we have written the entire code in Form Entry subroutine.

In the Z program we have called a FM "SD_SALESDOCUMENT_CREATE", to create a sales order.

After sales order is created we have used a Commit statement.

If I run the Z program individually, Salesorder gets created perfectly.

How ever as per scenario when trying to save the invoice, output type gets picked. But program doesn't get called.

and when I go to the saved the invoice I get the following error immediately:

"Error document - Update was terminated"

I have found that the problem is with COMMIT statement through transaction SM13.

Can anybody help me with this. I cannot save the sales order without COMMIT, so I have to use it.

Thanks in Advance,

Rohan.

8 REPLIES 8

Former Member
0 Kudos

If I am not mistaking u r triggering the output type whenever the application is saved. If that is true SAP is calling ur zprog. in update task. And update task triggers when commit work statement is issued by the invoice program at the time of saving the invoice. And within ur zprogram u r using 2nd commit statement that means it is nothing but commit inside a commit. Which is not allowed. So to avoid ur prob. just remove the commit from ur program. i.e. remove it after SD_SALESDOCUMENT_CREATE call.

If SAP calls ur code from update task then commit is not required in ur zprogram. Pl. check.

Regards,

JOy.

0 Kudos

Hi Joy,

Thanks for your response,

I have removed commit in my Z program.

But again the error remains, because inside the standard Function module "SD_SALESDOCUMENT_CREATE",

there is a Commit getting called in some include.

Can you help in how to overcome this?

Thanks in advance,

rohan.

0 Kudos

Try to use BAPis like:

BAPI_SALESORDER_CREATEFROMDAT1

BAPI_SALESORDER_CREATEFROMDAT2

These FMs do not use commit statement from inside...

Regards,

Joy.

Former Member
0 Kudos

Hi Rohan,

I have worked on almost similar kind of requirement as you.

"Error document - Update was terminated" is because saving of invoice is done in u201CUpdate Tasku201D. Again in that work process, FM also calls for update task, which is not allowed and give short dump.

Here are two different approaches to cope up in this scenario.

1.Call FM in NEW TASK.

Calling Function module in new task will assign new work process and will use different update task.

Use:

CALL FUNCTION 'SD_SALESDOCUMENT_CREATE' STARTING NEW TASK 'task'

This will not give update termination error.

Call of FM in this way will work, but as this will be asynchronies call you will be not able to get status/message out of the FM call result.

If capturing return message is mandatory, use below approach

2, Process output type via Job

Set output type, dispatch time u201CSend with periodically scheduled jobu201D in u201CDefault valueu201D tab.

Run batch job for program u201CRSNAST00u201D with appropriate variant.

Please let me know if you need any further details.

Best Regards,

Nisarg

0 Kudos

Hi Rohan,

I have achieved the similar requirement. Inside the form_entry subroutine we have triggered the event on Custom Business Object. And this event was linked to standard task. In the standard task, we have called method of the custom business object. In the method we have written our logic. We have passed NAST structure in the event container.

Hope this helps.

Regards,

Akash Modi

0 Kudos

Hi Nisarg,

Thanks for your reply.

Well the first approach doesn't suit our requirement as we need to create credit memo invoice from the new sales order created.

Coming to the second approach, How can we schedule the job when trying to save the invoice.

I output type gets picked when we save the invoice. To this output type is assigned our custom Z program. So this all happens automatically, how can we manually schedule the job periodically?

Please suggest on this.

Thanks in Advance,

Rohan.

0 Kudos

Hi Akash,

Thanks for you reply.

I understand the logic you have suggested.

Could please help me with sample code on how to trigger this event and code in the method if possible?

Will there be any problem with commit statement in the method or any Update terminated error?

Thanks in Advance,

Rohan.

0 Kudos

Hi Rohan,

Sorry, I could not got why first approach didnu2019t fit to your requirement. Your output type associated Z Program is calling FM SD_SALESDOCUMENT_CREATE, so just need to call with FM addition "STARTING NEW TASK". Do you have any dependent code after FM call?

Anyway, about second approach: If you set output type u201CSend with periodically scheduled jobu201D, than whenever you save Invoice, output type will be selected but will not be processed immediately (o/p status will be "orange" light).

So now, whenever you save invoice, your output get selected and required date has been populated in NAST. Actual processing is not done yet.

Schedule a periodic job in SM36 for RSNAST00 (periodic with time interval as per your requirement). This job will process outputs which are created and not yet processed during above step.

For example: if you have scheduled a job to run every 5 mins, this job will automatically process o/p for invoice saved during last fine minute if any.

Regards

Nisarg