Function module for creating order with reference to order is “SD_SALES_DOCUMENT_COPY“. Let’s check out the sample code for the same

*&---------------------------------------------------------------------*
*& Report ZTEST_COPY_SALES_ORDER
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ztest_copy_sales_order.
DATA: ls_vbakkom TYPE vbakkom,
      ls_vbak    TYPE vbak.

"Selection screen
PARAMETERS:pa_order TYPE vbeln_va.


*----------------------------------------------------------------------*
* 01. initialization                                                   *
*----------------------------------------------------------------------*
* a) BAPIs run without dialog                                          *
CALL FUNCTION 'DIALOG_SET_NO_DIALOG'.
* b) call beleg_initialisieren                                         *
CALL FUNCTION 'SD_SALES_DOCUMENT_INIT'
  EXPORTING
    simulation_mode_bapi = space.
*----------------------------------------------------------------------*
* 02. copy the document                                                *
*----------------------------------------------------------------------*
CALL FUNCTION 'SD_SALES_DOCUMENT_COPY'
  EXPORTING
    i_auarn        = 'TA'
    i_vbeln        = pa_order
    call_from_bapi = 'X'
  IMPORTING
    fvbakkom       = ls_vbakkom
  EXCEPTIONS
    error_message  = 01.
CHECK sy-subrc = 0.
*----------------------------------------------------------------------*
* 03. save the new document                                            *
*----------------------------------------------------------------------*
CALL FUNCTION 'SD_SALES_DOCUMENT_SAVE'
  IMPORTING
    evbak         = ls_vbak
  EXCEPTIONS
    error_message = 01.
IF sy-subrc EQ 0.
  COMMIT WORK AND WAIT.
  WRITE ls_vbak-vbeln.
ENDIF.

Here in the above code function module, DIALOG_SET_NO_DIALOG is used so that there is should not any pop-up screen interrupt during the creation of the sales order/subsequent document.

SD_SALES_DOCUMENT_INIT – This function module is used for initializing the variable and refreshing the memory.

SD_SALES_DOCUMENT_SAVE – This Function module will create a number range for the sales order which was copied from the reference document.

Report execution:

SE38 Report Execution
Here reference order is taken as 98
Result screen
New sales order 32346 created with reference to 98
VA03 Screen
Sales order in VA03

To create a sales order in SAP, we use VA01 Transaction. If you want to copy one order with reference to another order then the following steps can be performed on the VA01 transaction

VA01 - Create with Reference
VA01 Transaction

Note: You can use the is function module to create a subsequent document like from Inquiry to order creation etc.

Function module for creating order with reference to order
Function module Documentation

Additionally, if you face any authorization related issues while using the FM then please check out the OSS 2385088

Also, remember to use the statement COMMIT WORK AND WAIT else sometimes it will generate the number range for the sales order but it will not create sales order in the system.

Check out our ABAP Blogs ABAP – ABAP Skill

Check out our OData Series OData – ABAP Skill


0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *