Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use ABAP code to create Sales Order in S/4HANA

Shulou Source: shulou.com Published: 2022-06-02 09:24:47 10月06日 Update

This article mainly introduces how to use ABAP code to create Sales Order in S/4HANA. The introduction in this article is very detailed and has certain reference value. Interested friends must read it!

Below is a screenshot of S/4HANA's Sales Order created using ABAP code:

The values in red are hardcoded in my code, and blue are created by the SD_SALESDEVICE_CREATE function itself.

Take a look at the code:

DATA: ls_header TYPE bapisdhd1,ls_headerx TYPE bapisdhd1x,lt_bapiret2 LIKE bapiret2 OCCURS 0 WITH HEADER LINE,po_order_number TYPE bapivbeln-vbeln,lt_partners TYPE TABLE OF bapiparnr,ls_partners LIKE LINE OF lt_partners.ls_header-serv_date = '20200101'.ls_header-doc_type = 'TA'. "Type of sales order ls_header-comp_cde_b = '0001'. "Company Code ls_headerx-comp_cde_b ='X '.ls_headerx-doc_type ='X'.ls_headerx-updateflag ='I '. "Specify modification mode as I-create ls_partners-part_role ='WE '. "ship to partyls_partners-partn_numb = '0000000001'. "This customer master must exist in database table KNA1 APPEND ls_partners TO lt_partners.ls_partners-partn_role ='AG '. " sold to partyls_partners-partn_numb = '0000000001'.APPEND ls_partners TO lt_partners. "Call BAPI: CALL FUNCTION 'SD_SALESDEVICE_CREATE'EXPORTINGsales_header_in = ls_headersales_header_inx = ls_headerxint_number_assignment = 'X'IMPORTINGsalesdocument_ex = po_order_numberTABLESreturn = lt_bapiret2sales_partners = lt_partners.LOOP AT lt_bapiret2 ASSIGNING FIELD-SYMBOL() WHERE type = 'E'.WRITE:/ 'Error:', -message COLOR COL_NEGATIVE.RETURN.ENDLOOP.IF po_order_number IS INITIAL.WRITE:/ 'PO number initial'.RETURN.ENDIF.CLEAR: lt_bapiret2.CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'EXPORTINGwait = 'X'IMPORTINGreturn = lt_bapiret2.

That's all for the article "How to create Sales Order in S/4HANA using ABAP code." Thank you for reading! Hope to share the content to help everyone, more relevant knowledge, welcome to pay attention to the industry information channel!

Tags: Code content data article following figure value company interest function region customer buddy partner screenshot database more schema knowledge type red Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Linux Docker OPPO Reno NVidia