SAP-ABAP BAPI修改采购订单BOM

SAP-ABAP BAPI修改采购订单BOM

DATA: pocomponent LIKE TABLE OF bapimepocomponent WITH HEADER LINE,
pocomponentx LIKE TABLE OF bapimepocomponentx WITH HEADER LINE,
return LIKE TABLE OF bapiret2 WITH HEADER LINE.

****删除组件
REFRESH:pocomponent,pocomponentx,return.

LOOP AT gt_show INTO gs_show WHERE sel = ‘X’.

CLEAR:pocomponent,pocomponentx.

pocomponent-po_item    = gs_show-ebelp. "采购凭证的项目编号
pocomponent-sched_line = gs_show-ebele.
pocomponent-item_no    = gs_show-rspos.
pocomponent-change_id  = 'D'.
pocomponent-material   = gs_show-matnr."物料号
pocomponent-entry_quantity = gs_show-bdmng. "组件的需求数量
pocomponent-entry_uom  = gs_show-meins."单位
pocomponent-entry_uom_iso  = gs_show-meins."单位
pocomponent-plant      = gs_show-werks."工厂
pocomponent-req_date   = gs_show-bdter .
pocomponent-item_cat   = 'L'.   "3 OR L  LXF
pocomponent-base_uom   =  gs_show-meins."单位
pocomponent-base_uom_iso = gs_show-meins."单位
APPEND pocomponent.

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

ENDLOOP.

CHECK pocomponent[] IS NOT INITIAL.

CALL FUNCTION ‘BAPI_PO_CHANGE’
EXPORTING
purchaseorder = p_ebeln6
TABLES
return = return
pocomponents = pocomponent
pocomponentsx = pocomponentx.

READ TABLE return WITH KEY type = ‘E’.
IF sy-subrc NE 0.
CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’
EXPORTING
wait = ‘X’.

********************user_name
CALL METHOD cl_gui_frontend_services=>get_user_name
CHANGING
user_name = winuser
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
OTHERS = 4.

CALL METHOD cl_gui_cfw=>flush
  EXCEPTIONS
    cntl_system_error = 1
    cntl_error        = 2
    OTHERS            = 3.

********************user_name
CLEAR:row,id.
LOOP AT gt_show INTO gs_show WHERE sel = ‘X’.
DELETE gt_show INDEX sy-tabix.

  SELECT MAX( zitem ) INTO @DATA(lv_zitem) FROM zcpo WHERE ebeln = @gs_show-ebeln AND ebelp = @gs_show-ebelp AND etenr = @gs_show-ebele.
  row = lv_zitem + 1.
  SELECT MAX( banci ) INTO @DATA(lv_banci) FROM zcpo WHERE ebeln = @gs_show-ebeln AND ebelp = @gs_show-ebelp AND etenr = @gs_show-ebele.
  id = lv_banci + 1.

  CLEAR wa_zcpo.
  wa_zcpo-mandt = sy-mandt.
  wa_zcpo-ebeln = gs_show-ebeln.
  wa_zcpo-ebelp = gs_show-ebelp.
  wa_zcpo-etenr = gs_show-ebele.
  wa_zcpo-zitem = row.
  wa_zcpo-edate = sy-datum.
  wa_zcpo-aezei = sy-uzeit.
  wa_zcpo-aenam = sy-uname.
  wa_zcpo-ename = winuser.
  wa_zcpo-banci = id.
  wa_zcpo-tcode = sy-tcode.
  wa_zcpo-rsnum   = gs_show-rsnum.
  wa_zcpo-rspos   = gs_show-rspos.
  wa_zcpo-idnrk   = gs_show-matnr.
  wa_zcpo-stype   = '组件编号'.
  wa_zcpo-ranew   = gs_show-matnr.
  wa_zcpo-chngind = 'D'.
  MODIFY zcpo FROM wa_zcpo.

  wa_zcpo-stype   = '需求数量'.
  wa_zcpo-ranew   = gs_show-bdmng.
  wa_zcpo-chngind = 'D'.
  row = row + 1.
  wa_zcpo-zitem = row.
  MODIFY zcpo FROM wa_zcpo.

ENDLOOP.

MESSAGE '已删除' TYPE 'S'.

ELSE.

LOOP AT return WHERE type = 'E'.
  CONCATENATE lv_mess '/' return-message INTO lv_mess SEPARATED BY space.
ENDLOOP.

CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

LOOP AT gt_show INTO gs_show WHERE sel = 'X'.

  gs_show-incon = icon_red_light.
  gs_show-mess = lv_mess.
  MODIFY gt_show FROM gs_show TRANSPORTING incon mess.

ENDLOOP.

ENDIF.

********修改
REFRESH:pocomponent,pocomponentx,return.

LOOP AT gt_show INTO gs_show WHERE sel = ‘X’.

CLEAR:pocomponent,pocomponentx.

pocomponent-po_item    = gs_show-ebelp. "采购凭证的项目编号
pocomponent-sched_line = gs_show-ebele.
pocomponent-item_no    = gs_show-rspos.
IF gs_show-ind = 'I'.
  lv_flag = 'X'.
  pocomponent-change_id  = 'I'.
  pocomponent-entry_quantity = gs_show-bdmng. "组件的需求数量
ELSE. "M
  pocomponent-change_id  = 'U'.
  pocomponent-entry_quantity = gs_show-xgsl. "组件的需求数量
ENDIF.
pocomponent-material   = gs_show-matnr."物料号
pocomponent-entry_uom  = gs_show-meins."单位
pocomponent-entry_uom_iso  = gs_show-meins."单位
pocomponent-plant      = gs_show-werks."工厂
pocomponent-req_date   = gs_show-bdter .
pocomponent-item_cat   = 'L'.   "3 OR L  LXF
pocomponent-base_uom   =  gs_show-meins."单位
pocomponent-base_uom_iso = gs_show-meins."单位
APPEND pocomponent.

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

ENDLOOP.

CHECK pocomponent[] IS NOT INITIAL.

IF lv_flag = ‘X’.
REFRESH:it_resb_o.
SELECT * INTO TABLE it_resb_o FROM resb WHERE ebeln = p_ebeln6 AND ebelp = p_ebelp6.
SORT it_resb_o BY rsnum rspos.
ENDIF.

CALL FUNCTION ‘BAPI_PO_CHANGE’
EXPORTING
purchaseorder = p_ebeln6
TABLES
return = return
pocomponents = pocomponent
pocomponentsx = pocomponentx.

READ TABLE return WITH KEY type = ‘E’.
IF sy-subrc NE 0.
CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’
EXPORTING
wait = ‘X’.

"新生成的预留编号取到内表
IF lv_flag = 'X'.
  REFRESH:it_resb_n.
  SELECT * INTO TABLE it_resb_n FROM resb WHERE ebeln = p_ebeln6 AND ebelp = p_ebelp6.

  LOOP AT it_resb_n .
    lv_tabix = sy-tabix.

    READ TABLE it_resb_o WITH KEY rsnum = it_resb_n-rsnum
                                  rspos = it_resb_n-rspos BINARY SEARCH.
    IF sy-subrc = 0.
      DELETE it_resb_n INDEX lv_tabix.
    ENDIF.
  ENDLOOP.
ENDIF.

********************user_name
CALL METHOD cl_gui_frontend_services=>get_user_name
CHANGING
user_name = winuser
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
OTHERS = 4.

CALL METHOD cl_gui_cfw=>flush
  EXCEPTIONS
    cntl_system_error = 1
    cntl_error        = 2
    OTHERS            = 3.

********************user_name
CLEAR:row,id.

LOOP AT gt_show INTO gs_show WHERE sel = 'X'.

  SELECT MAX( zitem ) INTO @DATA(lv_zitem) FROM zcpo WHERE ebeln = @gs_show-ebeln AND ebelp = @gs_show-ebelp AND etenr = @gs_show-ebele.
  row = lv_zitem + 1.
  SELECT MAX( banci ) INTO @DATA(lv_banci) FROM zcpo WHERE ebeln = @gs_show-ebeln AND ebelp = @gs_show-ebelp AND etenr = @gs_show-ebele.
  id = lv_banci + 1.

  CLEAR wa_zcpo.
  wa_zcpo-mandt = sy-mandt.
  wa_zcpo-ebeln = gs_show-ebeln.
  wa_zcpo-ebelp = gs_show-ebelp.
  wa_zcpo-etenr = gs_show-ebele.
  wa_zcpo-zitem = row.
  wa_zcpo-edate = sy-datum.
  wa_zcpo-aezei = sy-uzeit.
  wa_zcpo-aenam = sy-uname.
  wa_zcpo-ename = winuser.
  wa_zcpo-banci = id.
  wa_zcpo-tcode = sy-tcode.
  wa_zcpo-rsnum   = gs_show-rsnum.
  wa_zcpo-rspos   = gs_show-rspos.
  wa_zcpo-idnrk   = gs_show-matnr.

  IF gs_show-ind = 'I'.
    READ TABLE it_resb_n WITH KEY matnr = gs_show-matnr.
    IF sy-subrc = 0.
      gs_show-rsnum = it_resb_n-rsnum.
      gs_show-rspos = it_resb_n-rspos.
    ENDIF.

    REFRESH:gs_show-f_style.
    stylelin-style = cl_gui_alv_grid=>mc_style_disabled.
    stylelin-fieldname = 'BDMNG'.
    APPEND stylelin TO gs_show-f_style.
    stylelin-fieldname = 'MATNR'.
    APPEND stylelin TO gs_show-f_style.

    gs_show-ind = 'M'.
    gs_show-incon = icon_green_light.
    gs_show-mess = '已保存'.

    MODIFY gt_show FROM gs_show TRANSPORTING rsnum rspos f_style ind incon mess.

    wa_zcpo-rsnum   = gs_show-rsnum.
    wa_zcpo-rspos   = gs_show-rspos.
    wa_zcpo-idnrk   = gs_show-matnr.

    wa_zcpo-stype   = '组件编号'.
    wa_zcpo-ranew   = gs_show-matnr.
    wa_zcpo-chngind = 'I'.
    wa_zcpo-zitem = row.
    MODIFY zcpo FROM wa_zcpo.

    wa_zcpo-stype   = '需求数量'.
    wa_zcpo-ranew   = gs_show-bdmng.
    wa_zcpo-chngind = 'I'.
    row = row + 1.
    wa_zcpo-zitem = row.
    MODIFY zcpo FROM wa_zcpo.

  ELSE.
    IF gs_show-bdmng = gs_show-xgsl.
      gs_show-incon = icon_yellow_light.
      gs_show-mess = '无变化'.
      MODIFY gt_show FROM gs_show TRANSPORTING bdmng incon mess.
    ELSE.

      wa_zcpo-rsnum   = gs_show-rsnum.
      wa_zcpo-rspos   = gs_show-rspos.
      wa_zcpo-idnrk   = gs_show-matnr.
      wa_zcpo-stype   = '需求数量'.
      wa_zcpo-ranew   = gs_show-xgsl.
      wa_zcpo-raold   = gs_show-bdmng.
      wa_zcpo-chngind = 'U'.
      row = row .
      wa_zcpo-zitem = row.
      MODIFY zcpo FROM wa_zcpo.


      gs_show-bdmng = gs_show-xgsl.
      gs_show-incon = icon_green_light.
      gs_show-mess = '已保存'.
      MODIFY gt_show FROM gs_show TRANSPORTING bdmng incon mess.

    ENDIF.
  ENDIF.
ENDLOOP.

MESSAGE '已保存' TYPE 'S'.

ELSE.

LOOP AT return WHERE type = 'E'.
  CONCATENATE lv_mess '/' return-message INTO lv_mess SEPARATED BY space.
ENDLOOP.

CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.


LOOP AT gt_show INTO gs_show WHERE sel = 'X'.

  gs_show-incon = icon_red_light.
  gs_show-mess = lv_mess.
  MODIFY gt_show FROM gs_show TRANSPORTING incon mess.

ENDLOOP.

ENDIF.

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值