SAP 委外订单BAPI(自动BOM,手工修改组件)

数据定义: 

DATA: poheader TYPE bapimepoheader,
     poheaderx TYPE bapimepoheaderx,
     potextheader TYPE bapimepotextheader,
     potextheader TYPE TABLE OF bapimepotextheader,
     poitem TYPE TABLE OF bapimepoitem WITH HEADER LINE,
     poitemx TYPE TABLE OF bapimepoitemx WITH HEADER LINE,
     poschedule TYPE TABLE OF bapimeposchedule WITH HEADER LINE,
     poschedulex TYPE TABLE OF bapimeposchedulx WITH HEADER LINE,
     pocomponent LIKE TABLE OF bapimepocomponent   WITH HEADER LINE, 
     pocomponentx LIKE TABLE OF bapimepocomponentx WITH HEADER LINE,
     return LIKE TABLE OF bapiret2 WITH HEADER LINE.

抬头:

  poheader-doc_type    =  订单类型
  poheader-vendor       = 供应商
  poheader-purch_org    = 采购组织
  poheader-pur_group    = 采购组
  poheader-comp_code    = 公司代码
  poheader-doc_date     = sy-datum.
  poheader-creat_date   = sy-datum.
  poheader-langu        = sy-langu.

  poheaderx-po_number   = 'X'.
  poheaderx-doc_type    = 'X'.
  poheaderx-vendor      = 'X'.
  poheaderx-purch_org   = 'X'.
  poheaderx-pur_group   = 'X'.
  poheaderx-comp_code   = 'X'.
  poheaderx-doc_date    = 'X'.
  poheaderx-creat_date  = 'X'.
  poheaderx-langu       = 'X'.

行项目:

    CLEAR: poitem,poitemx.
    poitem-po_item      = 采购凭证的项目编号
    poitem-material     = 物料
    poitem-item_cat     = 项目类别
    poitem-quantity     =  采购订单数量
    poitem-plant         = 工厂
    poitem-stge_loc     = 库存地点
    poitem-po_unit      = 单位
    APPEND poitem.
    poitemx-po_item     = po_item. "采购凭证的项目编号
    poitemx-material    = 'X'.
    poitemx-quantity    = 'X'."采购订单数量
    poitemx-item_cat    = 'X'."项目类别
    poitemx-plant       = 'X'."工厂
    poitemx-stge_loc     = 'X'."库存地点
    poitemx-po_unit     = 'X' ."采购订单的计量单位
    APPEND poitemx.

计划行:

    CLEAR: poschedule,poschedulex.
    poschedule-po_item = 采购凭证的项目编号
    poschedule-sched_line =  采购凭证的项目编号
    poschedule-del_datcat_ext = 'D'."交货日期的类别
    poschedule-delivery_date = s_erdat. "交货日期
    APPEND poschedule.

   poschedulex-po_item = po_item. "采购凭证的项目编号
   poschedulex-sched_line = sched_line."GW_MAIN-EBELP'. "采购凭证的项目编号
   poschedulex-del_datcat_ext = 'X'."交货日期的类别
   poschedulex-delivery_date = 'X'."交货日期
    APPEND poschedulex.

CALL FUNCTION 'BAPI_PO_CREATE1'
    EXPORTING
      poheader         = poheader
      poheaderx       = poheaderx
    IMPORTING
      exppurchaseorder = l_ebeln 订单号存储
    TABLES
      return           = return
      poitem           = poitem
      poitemx          = poitemx
      poschedule       = poschedule
      poschedulex      = poschedulex
      pocomponents     = pocomponent
      pocomponentsx   = pocomponentx.                                                                                            
     " extensionin      = ext.
  LOOP AT return INTO return WHERE type = 'E' OR type = 'A'.
    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK' .
  ENDLOOP.
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
      wait = 'X'.

组件:更新 U,插入 I,删除 D

    pocomponent-po_item    = po_item. "采购凭证的项目编号
    pocomponent-sched_line = sched_line.
    pocomponent-item_no    = 0010.
    pocomponent-material   = "物料号
    pocomponent-entry_quantity = "组件的需求数量
    pocomponent-entry_uom  = 单位
    pocomponent-entry_uom_iso  = 单位
    pocomponent-plant      = 工厂
    pocomponent-req_date   = s_erdat .
    pocomponent-change_id  = 'U'.
    pocomponent-item_cat   = 'L'.   "3 OR L  LXF
    pocomponent-base_uom   =  单位
    pocomponent-base_uom_iso = 单位
    pocomponent-iss_st_loc   =  工厂
    APPEND pocomponent.

    pocomponentx-po_item    = it_pocomponent-po_item. "采购凭证的项目编号
    pocomponentx-sched_line = it_pocomponent-sched_line.
    pocomponentx-item_no    = 0010.
    pocomponentx-material =  'X'. "物料号组件的需求数量采购凭证的项目编号
    pocomponentx-entry_quantity = 'X'. "组件的需求数量
    pocomponentx-entry_uom = 'X'.
    pocomponentx-entry_uom_iso  = 'X'.
    pocomponentx-plant    =  'X'. "工厂
    pocomponentx-req_date    =  'X'.
    pocomponentx-change_id = 'X'.
    pocomponentx-item_cat = 'X'.
    pocomponentx-base_uom = 'X'.
    pocomponentx-base_uom_iso  = 'X'.
    pocomponentx-iss_st_loc = 'X'.
    APPEND it_pocomponentx.

CALL FUNCTION 'BAPI_PO_CHANGE'
    EXPORTING
      purchaseorder = l_ebeln
    TABLES
      return        = return
      pocomponents  = pocomponent
      pocomponentsx = pocomponentx.

  READ TABLE it_return WITH KEY type = 'E'.
  IF sy-subrc NE 0.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait = 'X'.
  ELSE.
    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
  ENDIF.

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值