使用ABAP程式碼建立S/4HANA裡的Sales Order
阿新 • • 發佈:2018-11-10
下圖是使用ABAP程式碼建立的S/4HANA的Sales Order的截圖:
其中紅色區域的值是我程式碼裡硬編碼的,而藍色是函式SD_SALESDOCUMENT_CREATE自己建立的。
來看下程式碼:
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'. “銷售訂單的型別 ls_header-comp_cde_b = '0001'. ” 公司程式碼 ls_headerx-comp_cde_b = 'X'. ls_headerx-doc_type = 'X'. ls_headerx-updateflag = 'I'. “ 指定修改模式為I-建立 ls_partners-partn_role = 'WE'. "ship to party ls_partners-partn_numb = '0000000001'. ”這個客戶主資料在資料庫表KNA1裡必須存在 APPEND ls_partners TO lt_partners. ls_partners-partn_role = 'AG'. " sold to party ls_partners-partn_numb = '0000000001'. APPEND ls_partners TO lt_partners. “呼叫BAPI: CALL FUNCTION 'SD_SALESDOCUMENT_CREATE' EXPORTING sales_header_in = ls_header sales_header_inx = ls_headerx int_number_assignment = 'X' IMPORTING salesdocument_ex = po_order_number TABLES return = lt_bapiret2 sales_partners = lt_partners. LOOP AT lt_bapiret2 ASSIGNING FIELD-SYMBOL(<return>) WHERE type = 'E'. WRITE:/ 'Error:', <return>-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' EXPORTING wait = 'X' IMPORTING return = lt_bapiret2.
要獲取更多Jerry的原創文章,請關注公眾號"汪子熙":