Skip to Content
0

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

Jun 08, 2017 at 12:04 PM

123

avatar image

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.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Mike Pokraka Jun 08, 2017 at 12:15 PM
0

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.

Share
10 |10000 characters needed characters left characters exceeded
Raymond Giuseppi
Jun 08, 2017 at 12:16 PM
0

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.

Show 9 Share
10 |10000 characters needed characters left characters exceeded

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

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
Raymond Giuseppi

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

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
Raymond Giuseppi

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

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

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
Show more comments

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

0
Shanthi Kumar Juluru Jun 13, 2017 at 12:20 PM
0

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.

Show 2 Share
10 |10000 characters needed characters left characters exceeded

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

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.

0