Skip to end of metadata
Go to start of metadata

This code snippet will create the sales order using BAPI.

REPORT z_sales_create.
DATA:
  fs_patnr TYPE bapipartnr,
  t_patnr LIKE STANDARD TABLE OF fs_patnr.
*------------------------Data Declaration----------------------------*
DATA:
  st_bapisdhead LIKE bapisdhead, " Sales Order Header Data
  ta_bapiitemin LIKE bapiitemin OCCURS 0 WITH HEADER LINE," Ln item
  d_bapireturn1 LIKE bapireturn1, " Bapi return msg
  d_vbeln LIKE bapivbeln-vbeln. " Sales Order Number
* Move the data to create sales order in the repective parameters------*
MOVE:
  'TA' TO st_bapisdhead-doc_type, " Sales document type
  '1' TO st_bapisdhead-purch_no_c,
  '0001' TO st_bapisdhead-sales_org,
  '01' TO st_bapisdhead-distr_chan,
  '01' TO st_bapisdhead-division.
MOVE:
  'AG' TO fs_patnr-partn_role," Sold to Party
  '0000000001' TO fs_patnr-partn_numb.
APPEND fs_patnr TO t_patnr.
CLEAR fs_patnr.
MOVE:
  'WE' TO fs_patnr-partn_role," Shipto Party
  '0000000001' TO fs_patnr-partn_numb.
APPEND fs_patnr TO t_patnr.
CLEAR fs_patnr.
MOVE:
  'PC' TO ta_bapiitemin-material,
  '0001' TO ta_bapiitemin-plant,
  '1' TO ta_bapiitemin-req_qty.
APPEND ta_bapiitemin.
* Call the Bapi to create the sales order
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT1'
  EXPORTING
    order_header_in = st_bapisdhead
  IMPORTING
    salesdocument   = d_vbeln
    return          = d_bapireturn1
  TABLES
    order_items_in  = ta_bapiitemin
    order_partners  = t_patnr.
IF sy-subrc EQ 0.
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
ENDIF.
IF d_vbeln <> space.
  WRITE: 'Sales order No. ', d_vbeln.
ENDIF.
 

The output will be as:

Sample Program to create sales order using BAPI
Sales order No.  837
  • No labels