下圖是使用ABAP代碼建立的S/4HANA的Sales Order的截圖:數據庫
其中紅色區域的值是我代碼裏硬編碼的,而藍色是函數SD_SALESDOCUMENT_CREATE本身建立的。 api
來看下代碼:函數
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的原創文章,請關注公衆號"汪子熙":編碼