*"---------------------------------------------------------------------- *"*"本地接口: *" EXPORTING *" REFERENCE(O_RETURN) TYPE ZMMS0021 *" TABLES *" IT_ITEM STRUCTURE ZMMS0106 *"---------------------------------------------------------------------- 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."数量 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."数量 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. FREE MEMORY ID 'ZPOS_LGORT_FLAG'. DELETE lt_return WHERE type = 'E' AND id = 'BAPI' AND number = '001'. 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 = 0. "创建失败 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.