Skip to Content

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


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.

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

3 Answers

  • Jun 08, 2017 at 12:15 PM

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • Jun 08, 2017 at 12:16 PM

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • Jun 13, 2017 at 12:20 PM

    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.

    Add comment
    10|10000 characters needed characters exceeded

    • 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.