其他分享
首页 > 其他分享> > 函数使用十四:BAPI_PO_CREATE1

函数使用十四:BAPI_PO_CREATE1

作者:互联网

*&---------------------------------------------------------------------*
*& Report  ZBAPI_PO_CREATE2
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
"场景:因需求,采购部门将各业务部门的采购需求汇总,单独创建采购订单。
"根据
REPORT  zbapi_po_create2.

DATA:gw_head TYPE bapimepoheader,
     gw_headx TYPE bapimepoheaderx,
     gt_item TYPE TABLE OF bapimepoitem,
     gw_item LIKE LINE OF gt_item,
     gt_itemx TYPE TABLE OF bapimepoitemx,
     gw_itemx LIKE LINE OF gt_itemx,
     gt_return TYPE TABLE OF bapiret2,
     gw_return LIKE LINE OF gt_return,
     gt_sch    TYPE TABLE OF bapimeposchedule,
     gw_sch  LIKE LINE OF gt_sch,
     gt_schx TYPE TABLE OF bapimeposchedulx,
     gw_schx LIKE LINE OF gt_schx,
     gt_comp  TYPE TABLE OF bapimepocomponent,
     gw_comp LIKE LINE OF gt_comp,
     gt_compx TYPE TABLE OF bapimepocomponentx,
     gw_compx LIKE LINE OF gt_compx,
     gv_po    TYPE ebeln.

"header
gw_head-comp_code = '6375'.
*gw_head-comp_code = '8380'.
gw_head-doc_type = 'NB'.
gw_head-status = 'B'.
gw_head-creat_date = sy-datum.
gw_head-doc_date = sy-datum.
gw_head-purch_org = '6375'.
*gw_head-purch_org = '8380'.
gw_head-pur_group = 'D01'.
*gw_head-pur_group = '137'.
gw_head-vendor = '0000401210'.
*gw_head-vendor = '0000100031'.
gw_head-langu = 'E'.
gw_head-ref_1 = 'E'."Your Reference

gw_headx-comp_code = 'X'.
gw_headx-doc_type = 'X'.
gw_headx-status = 'X'.
gw_headx-creat_date = 'X'.
gw_headx-doc_date = 'X'.
gw_headx-purch_org = 'X'.
gw_headx-pur_group = 'X'.
gw_headx-vendor = 'X'.
gw_headx-langu = 'X'.
gw_headx-ref_1 = 'X'.

"PO行项目
gw_item-po_item = 10.
gw_item-material = 'K300000'.
gw_item-item_cat = 'L'.
*gw_item-material = 'T60602475'.
gw_item-plant = '6375'.
*gw_item-plant = '8380'.
*gw_item-STGE_LOC = '8380'.
gw_item-quantity = 2.
gw_item-net_price = 100.
gw_item-price_unit = 1.
gw_item-preq_no = '0010001627'.
gw_item-preq_item = 10.
*gw_item-batch = 'HS'.
APPEND gw_item TO gt_item.CLEAR:gw_item.

gw_itemx-po_item = 10.
gw_itemx-material = 'X'.
gw_itemx-item_cat = 'X'.
gw_itemx-plant = 'X'.
*gw_item-STGE_LOC = '8380'.
gw_itemx-quantity = 'X'.
gw_itemx-net_price = 'X'.
gw_itemx-price_unit = 'X'.
gw_itemx-preq_no = 'X'.
gw_itemx-preq_item = 'X'.
*gw_itemx-batch = 'X'.
APPEND gw_itemx TO gt_itemx.CLEAR:gw_itemx.

"PO计划行
gw_sch-po_item = 10.
gw_sch-sched_line = 1.
gw_sch-delivery_date = '20210605'.
gw_sch-com_date = sy-datum + 1.
gw_sch-po_date = sy-datum.
gw_sch-quantity = 2.
gw_sch-preq_no = '0010001627'.
gw_sch-preq_item = 10.
gw_sch-com_qty = 2.
APPEND gw_sch TO gt_sch.

gw_schx-po_item = 10.
gw_schx-sched_line = 1.
gw_schx-delivery_date = 'X'.
gw_schx-com_date = 'X'.
gw_schx-po_date = 'X'.
gw_schx-quantity = 'X'.
gw_schx-preq_no = 'X'.
gw_schx-preq_item = 'X'.
gw_schx-com_qty = 'X'.
APPEND gw_schx TO gt_schx.

*gw_comp-po_item = 10.
*gw_comp-sched_line = 1.
*gw_comp-item_no = 10.
*gw_comp-material = 'K100000'.
*gw_comp-entry_quantity = 1.
*gw_comp-plant = '6375'.
*gw_comp-change_id = 'I'.
**gw_comp-plant = '8380'.
*APPEND gw_comp TO gt_comp.
*
*gw_compx-po_item = 10.
*gw_compx-sched_line = 1.
*gw_compx-item_no = 10.
*gw_compx-material = 'X'.
*gw_compx-entry_quantity = 'X'.
*gw_compx-plant = 'X'.
*gw_compx-change_id = 'X'.
*APPEND gw_compx TO gt_compx.

CALL FUNCTION 'BAPI_PO_CREATE1'
  EXPORTING
    poheader         = gw_head
    poheaderx        = gw_headx
  IMPORTING
    exppurchaseorder = gv_po
  TABLES
    return           = gt_return
    poitem           = gt_item
    poitemx          = gt_itemx
    poschedule       = gt_sch
    poschedulex      = gt_schx
    pocomponents     = gt_comp
    pocomponentsx    = gt_compx.
READ TABLE gt_return INTO gw_return WITH KEY type = 'E'.
IF sy-subrc = 0.
  CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ELSE.
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
      wait = 'X'.
  WRITE gv_po.
ENDIF.

 

标签:gw,BAPI,gt,comp,itemx,item,CREATE1,head,PO
来源: https://www.cnblogs.com/sapSB/p/15497471.html