下图是使用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的原创文章,请关注公众号"汪子熙":