SAP ABAP 创建交货单BAPI_OUTB_DELIVERY_CREATE_SLS
DATA:lv_delivery TYPE bapishpdelivnumb-deliv_numb,
lv_ship_point TYPE bapidlvcreateheader-ship_point,
lv_due_date TYPE bapidlvcreateheader-due_date,
lt_sales_order_items LIKE TABLE OF bapidlvreftosalesorder,
ls_sales_order_items LIKE bapidlvreftosalesorder,
lt_return LIKE TABLE OF bapiret2,
ls_return LIKE bapiret2.
DATA:ls_vbap TYPE vbap,
lt_vbap TYPE TABLE OF vbap.
SELECT * "获取SO对应的数据
INTO CORRESPONDING FIELDS OF TABLE lt_vbap
FROM vbap
WHERE vbeln = u_vbeln.
LOOP AT lt_vbap INTO ls_vbap.
lv_ship_point = ls_vbap-vstel."装运点
ls_sales_order_items-ref_doc = ls_vbap-vbeln. "订单号
ls_sales_order_items-ref_item = ls_vbap-posnr. "行项目号
ls_sales_order_items-dlv_qty = ls_vbap-kwmeng. "数量
ls_sales_order_items-sales_unit = ls_vbap-vrkme. "单位
APPEND ls_sales_order_items TO lt_sales_order_items.
CLEAR:ls_sales_order_items.
ENDLOOP.
lv_due_date = "创建日期
CALL FUNCTION 'BAPI_OUTB_DELIVERY_CREATE_SLS' "创建dn
EXPORTING
ship_point = lv_ship_point
due_date = lv_due_date
IMPORTING
delivery = lv_delivery
TABLES
sales_order_items = lt_sales_order_items
return = lt_return.
IF lv_delivery IS NOT INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = abap_true.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ENDIF.