传入采购订单项目建交货单
FUNCTION zmmfmXXXX.
*"----------------------------------------------------------------------
*"*"本地接口:
*" EXPORTING
*" REFERENCE(O_RETURN) TYPE ZMMS0021
*" TABLES
*" IT_ITEM STRUCTURE ZMMS0185
*"----------------------------------------------------------------------
DATA:lt_stock_items TYPE TABLE OF bapidlvreftosto.
DATA:ls_stock_items TYPE bapidlvreftosto.
DATA:lt_created_items TYPE TABLE OF bapidlvitemcreated.
DATA:ls_created_items TYPE bapidlvitemcreated.
DATA:lv_delivery TYPE bapishpdelivnumb-deliv_numb.
DATA:lv_vstel TYPE vstel.
DATA:lv_ledat TYPE ledat.
DATA:lt_return TYPE TABLE OF bapiret2. LOOP AT it_item INTO DATA(ls_item).
ls_stock_items-ref_doc = ls_item-ebeln."参考凭证
ls_stock_items-ref_item = ls_item-ebelp."参考项
ls_stock_items-dlv_qty = ls_item-menge."数量
ls_stock_items-sales_unit = ls_item-meins."数量单位
APPEND ls_stock_items TO lt_stock_items. ls_created_items-ref_doc = ls_item-ebeln."参考凭证
ls_created_items-ref_item = ls_item-ebelp."参考项
ls_created_items-material = ls_item-matnr."物料编号
ls_created_items-material_long = ls_item-matnr."物料编号
ls_created_items-dlv_qty = ls_item-menge."数量
ls_created_items-sales_unit = ls_item-meins."数量单位
APPEND ls_created_items TO lt_created_items.
ENDLOOP. CALL FUNCTION 'BAPI_OUTB_DELIVERY_CREATE_STO'
EXPORTING
ship_point = lv_vstel
due_date = lv_ledat
IMPORTING
delivery = lv_delivery
TABLES
stock_trans_items = lt_stock_items
created_items = lt_created_items
return = lt_return. DELETE lt_return WHERE type = 'E' AND id = 'BAPI' AND number = ''. LOOP AT lt_return INTO DATA(ls_return) WHERE type = 'E'.
CONCATENATE o_return-message ls_return-message INTO o_return-message SEPARATED BY '/'.
ENDLOOP. IF sy-subrc = . "创建失败
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. o_return-type = 'E'.
CONCATENATE '交货单创建失败:' o_return-message INTO o_return-message. ELSE.
"创建成功
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'. o_return-zdjh = lv_delivery."交货单
o_return-type = 'S'.
o_return-message = '交货单创建成功'. ENDIF.
ENDFUNCTION.