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: 

Change sales order created in USEREXIT_SAVE_DOCUMENT after sales order number generation.

0 Kudos

Hi

I am trying to create PO number automatically while creating sales order . I am using USEREXIT_SAVE_DOCUMENT for this using BAPI BAPI_PO_CREATE1. Now after Po created, I need to update immediately the sales order with new PO number generated from BAPI. but if do changes to VBAK or XVBAK-BSTNK in the above user exit , changes are not reflecting . Old po is only considering which is giving in VA01 screen.

Can you please help me where we can write this change to update So after PO creation.

I need sales order number generated before calling above BAPI. so I have written the code in a FM above userexit.

Help me with any suggestions.

14 REPLIES 14

pokrakam
Active Contributor
0 Kudos

I would strongly advise against creating all this in one go. How are you going to handle situations where one or the other part fails?

Create the SO, create the PO, update the SO.

You can manage the processing sequence using output control, events, or workflow.

raymond_giuseppi
Active Contributor
0 Kudos

USEREXIT_SAVE_DOCUMENT is executed too late (update FM are already registered for update, no hope) so you could try to schedule the wrapper FM for BAPI_PO_CREATE1 in a background task/unit and consider calling BAPI_SALESORDER_CHANGE in the wrapper.

0 Kudos

hi Raymond,

Will sales order saved in the DB if I use above BAPI_SALESORDER_CHANGE to change the sales order. I hope still not order will not get saved in DB in the user exit USEREXIT_SAVE_DOCUMNET. Please correct me if I am wrong.

0 Kudos

At this step the SO is not yet in database but is already registered: the CALL FUNCTION IN UPDATE TASK were already called with the final values but are yet to be performed and update database. So call a RFC wrapper FM IN BACKGROUND TASK/UNIT that will execute both BAPI : creation of PO and update of SO in sequence) Don't call the SO BAPI at this step or you will mess with databas (if lucky you get a dump)

0 Kudos

Hi Raymond

Thanks . I will the above way. I will call both bapi's po create and SO change in a sequence in function module and will execute in background task in userexit USEREXIT_SAVE_DOCUMNET. I got this point.

Can you please let me know what is it with RFC call here. Do we need to required to make FM as RFC FM?

And also I don't understand the below point. can you please elaborate.

Don't call the SO BAPI at this step or you will mess with databas (if lucky you get a dump)

Can you please confirm in which step you are saying that i might be messing with DB.

0 Kudos

The wrapper FM called IN BACKGROUND must be RFC enabled (so parameters by value and not by reference)

In the case you didn't execute the FM in another LUW you could mix your data update with the current transaction and at best get a dump at worse mess with the data cause of sequence of updates, with IN BACKGROUND no problem. Read online Abap documentation on the CALL FUNCTION statement IN BACKGROUND option (as well as COMMIT WORK too)

0 Kudos

Hi Raymond,

As per you suggestion , I did call wrapper FM in background task to create PO from VA01. But you know this not updating immediately after sales order creation. A job is getting creating for this . I got know this job will call for every 15 min by scheduling program RSARFCSE. Can we do create PO automatically without job run? or at least is there a chance to make background task FM job run immediately after all SO updated LUW work done.

0 Kudos

Can we do this with any other additions like 'IN UPDATE TASK' or "STARTING NEW TASK'.? which will be best solution for this scenario?

0 Kudos

RSARFCSE is scheduled if and only if system is not available (did you add a destination to statement) usually the RFC FM are executed in sequence at end of V1 update FM.

0 Kudos

I have not added destination. But in my case there is no destination. In my current system itself i need to call this wrapper FM to be execute to create PO from VA01.

What if i add destination 'NONE' with BACKGROUND task addition. Will it execute the FM with immediate effect without job scheduling.

0 Kudos

No, NONE is default value, Check with your Basis if execution is not immed.

former_member194575
Active Participant
0 Kudos

I think you can trigger an output with a special function and it has the BAPI to create PO. You can create a background job and it will process all outputs that are created. This way we can have proper error handling.

0 Kudos

Hi Kumar,

can you please elaborate your approach? Please send me the steps to do it. where we can call BAPI exactly in a special function in output trigger for va01? what kind of special function ?

0 Kudos

We should call BAPI in output program. Please see the approach below.

1. New output type should be configured for the sales order and it will get populated upon maintaining output condition records.

2. Output type transmission medium should be '8' special function and make dispatch time '1'. Inside this program, you can call BAPI to create PO. With the sales order number, you can pull other required data and pass it onto BAPI.

3. Finally, you can schedule RSNAST00 program in background for this output type.

Let me know if you need more information.