使用BAPI_NETWORK_COMP_*实现生产订单组件的增删改查

1、文档说明

对于生产订单组件的增删改有多种办法,比较常用的有使用内部函数CO_XT_COMPONENT_*,有改造BAPI_ALM_ORDER_MAINTAIN来实现,各有千秋。

本文档介绍,通过PS的BAPI_NETWORK_COMP_*系列BAPI,来实现常见的组件先删后建的覆盖式操作,组件部分字段修改,组件信息查询等功能

2、BAPI用法

2.1、组件列表查询

查询组件基本数据

"--------------------@斌将军--------------------
DATA:lv_number          TYPE bapi_network_list-network,
     ls_return          TYPE bapiret2,
     lt_activity        TYPE TABLE OF bapi_network_comp_act_rng,
     lt_components_list TYPE TABLE OF bapi_network_comp_list.

lv_number = '000001001211'."工单号

CALL FUNCTION 'BAPI_NETWORK_COMP_GETLIST'
  EXPORTING
    number            = lv_number
*   MAX_ROWS          = 0
  IMPORTING
    return            = ls_return
  TABLES
    i_activity_range  = lt_activity
    e_components_list = lt_components_list.
"--------------------@斌将军--------------------

使用BAPI_NETWORK_COMP_*实现生产订单组件的增删改查_第1张图片

2.2、组件列表详细信息查询

查询组件详细的数据

"--------------------@斌将军--------------------
DATA:lv_number TYPE bapi_network_list-network,
     lt_detail TYPE TABLE OF bapi_network_comp_detail.

lv_number = '000001001211'."工单号

CALL FUNCTION 'BAPI_NETWORK_COMP_GETDETAIL'
  EXPORTING
    number              = lv_number
  TABLES
    e_components_detail = lt_detail.
"--------------------@斌将军--------------------

使用BAPI_NETWORK_COMP_*实现生产订单组件的增删改查_第2张图片

2.3、组件删除

移除组件

"--------------------@斌将军--------------------
DATA:lv_number TYPE bapi_network_list-network,
     lt_remove  TYPE TABLE OF bapi_network_comp_id,
     ls_remove  TYPE bapi_network_comp_id,
     lt_message TYPE TABLE OF bapi_meth_message,
     ls_message TYPE bapi_meth_message.

DATA:lv_check   TYPE char1,
     lv_message TYPE char255.

"此处使用查询BAPI得到的组件列表,赋值给移除内表
LOOP AT lt_detail INTO ls_detail.
  CLEAR ls_remove.
  ls_remove-component = ls_detail-component.
  APPEND ls_remove TO lt_remove.
ENDLOOP.

lv_number = '000001001211'."工单号

CALL FUNCTION 'BAPI_NETWORK_COMP_REMOVE'
  EXPORTING
    number              = lv_number
  TABLES
    i_components_remove = lt_remove
    e_message_table     = lt_message.

LOOP AT lt_message INTO ls_message WHERE message_type CA 'AEX'.
  lv_check = 'E'.
  lv_message = lv_message && ls_message-message_text.
ENDLOOP.

IF lv_check = 'E'.
  CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ELSE.
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
      wait = abap_true.
ENDIF.
"--------------------@斌将军--------------------

2.4、组件新增

新增组件

"--------------------@斌将军--------------------
DATA:lv_number     TYPE bapi_network_list-network,
     lt_components TYPE TABLE OF bapi_network_comp_add,
     ls_components TYPE bapi_network_comp_add,
     lt_message    TYPE TABLE OF bapi_meth_message,
     ls_message    TYPE bapi_meth_message.

DATA:lv_check   TYPE char1,
     lv_message TYPE char255.

lv_number = '000001001211'."工单号

ls_components-item_number = '0030'."项目编号
ls_components-activity = '0010'."必输 作业
ls_components-material = '000000000003000135'."物料
ls_components-plant = 'P010'."工厂
ls_components-type_of_pur_resv = 'F'."beskz."必输 采购类型
ls_components-entry_quantity = 1."数量
ls_components-base_uom = 'KG'."单位
ls_components-backflush = 'X'."反冲
*ls_components-batch = ''."批次
ls_components-item_cat = 'L'."项目类别
APPEND ls_components TO lt_components.

CALL FUNCTION 'BAPI_PS_INITIALIZATION'.
CALL FUNCTION 'BAPI_NETWORK_COMP_ADD'
  EXPORTING
    number           = lv_number
  TABLES
    i_components_add = lt_components
    e_message_table  = lt_message.

LOOP AT lt_message INTO ls_message WHERE message_type CA 'AEX'.
  lv_check = 'E'.
  lv_message = lv_message && ls_message-message_text.
ENDLOOP.

IF lv_check = 'E'.
  CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ELSE.
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
      wait = abap_true.
ENDIF.
"--------------------@斌将军--------------------

使用BAPI_NETWORK_COMP_*实现生产订单组件的增删改查_第3张图片

2.5、组件修改

修改组件的数量和反冲标识。

其中修改工序时,同时修改反冲标识会不起作用,这个需要注意

"--------------------@斌将军--------------------
DATA:lv_number                   TYPE bapi_network_list-network,
     ls_return                   TYPE bapiret2,
     lt_components_change        TYPE TABLE OF bapi_network_comp_change,
     ls_components_change        TYPE bapi_network_comp_change,
     lt_components_change_update TYPE TABLE OF bapi_network_comp_cng_upd,
     ls_components_change_update TYPE bapi_network_comp_cng_upd,
     lt_message                  TYPE TABLE OF bapi_meth_message,
     ls_message                  TYPE bapi_meth_message.

DATA:lv_check   TYPE char1,
     lv_message TYPE char255.

lv_number = '000001001211'."工单号

CLEAR:ls_components_change.
ls_components_change-component = '00000039290006'."BAPI获取到的组件唯一标识
*ls_components_change-activity = '0020'."工序
ls_components_change-entry_quantity = 2."数量
ls_components_change-backflush = ''."反冲
APPEND ls_components_change TO lt_components_change.

CLEAR:ls_components_change_update.
ls_components_change_update-component = '00000039290006'.
*ls_components_change_update-activity = 'X'.
ls_components_change_update-entry_quantity = 'X'.
ls_components_change_update-backflush = 'X'.
APPEND ls_components_change_update TO lt_components_change_update.

CALL FUNCTION 'BAPI_PS_INITIALIZATION'.
CALL FUNCTION 'BAPI_NETWORK_COMP_CHANGE'
  EXPORTING
    number                     = lv_number
  IMPORTING
    return                     = ls_return
  TABLES
    i_components_change        = lt_components_change
    i_components_change_update = lt_components_change_update
    e_message_table            = lt_message.

LOOP AT lt_message INTO ls_message WHERE message_type CA 'AEX'.
  lv_check = 'E'.
  lv_message = lv_message && ls_message-message_text.
ENDLOOP.

IF lv_check = 'E'.
  CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ELSE.
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
      wait = abap_true.
ENDIF.
"--------------------@斌将军--------------------

使用BAPI_NETWORK_COMP_*实现生产订单组件的增删改查_第4张图片

定期更文,欢迎关注

使用BAPI_NETWORK_COMP_*实现生产订单组件的增删改查_第5张图片

你可能感兴趣的:(ABAP,ABAP,生产订单,BAPI,组件)