一、新增组件BAPI
DATA:lv_number LIKE bapi_network_list-network, lv_return LIKE bapiret2, lt_components TYPE TABLE OF bapi_network_comp_add, ls_components TYPE bapi_network_comp_add, lt_message_table TYPE TABLE OF bapi_meth_message WITH HEADER LINE, ls_message_table TYPE bapi_meth_message, lt_activity TYPE TABLE OF bapi_network_comp_act_rng WITH HEADER LINE, lt_components_list TYPE TABLE OF bapi_network_comp_list WITH HEADER LINE, lt_components_id TYPE TABLE OF bapi_network_comp_id WITH HEADER LINE, lt_components_detail TYPE TABLE OF bapi_network_comp_detail, ls_components_detail TYPE bapi_network_comp_detail, lt_components_remove TYPE TABLE OF bapi_network_comp_id WITH HEADER LINE, lt_components_change TYPE TABLE OF bapi_network_comp_change WITH HEADER LINE, lt_components_change_update TYPE TABLE OF bapi_network_comp_cng_upd WITH HEADER LINE. CALL FUNCTION 'BAPI_PS_INITIALIZATION'. "------------------------ADD---------------------------- LOOP AT lt_zin INTO ls_in. lv_number = ls_in-aufnr."网络编号 CLEAR:ls_components. ls_components-activity = ls_in-vornr."活动编号 ls_components-material = ls_in-matnr."物料编码 ls_components-plant = ls_in-werks."工厂 ls_components-entry_quantity = ls_in-bdmng."需求数量 * ls_components-base_uom = ls_in-VORNR."工厂 ls_components-req_date = ls_in-bdter."需求日期 ls_components-cost_relevant = 'X'."与成本核算相关标识 ls_components-item_cat = 'L'."项目类别 CASE ls_in-zqdlx. WHEN 'G1'. ls_components-type_of_pur_resv = '7'."生成WBS元素的初步采购需求 WHEN 'G2'. READ TABLE lt_marc INTO DATA(ls_marc) WITH KEY matnr = ls_in-matnr werks = ls_in-werks. IF ls_marc-sbdkz = '' OR ls_marc-sbdkz = '1'. ls_components-type_of_pur_resv = '8'."生成WBS预留 ELSEIF ls_marc-sbdkz = '2'. ls_components-type_of_pur_resv = '3'."生成网络预留 ENDIF. WHEN 'G3'. ls_components-type_of_pur_resv = '1'."网络的采购需求 ls_components-item_cat = 'N'."项目类别 WHEN OTHERS. ENDCASE. ls_components-mrp_relevant = '3'."预留相关性/生成采购申请(立即) ls_components-item_text = ls_in-zbz."长文本 APPEND ls_components TO lt_components. MOVE-CORRESPONDING ls_in TO ls_out. APPEND ls_out TO lt_zout. ENDLOOP. CALL FUNCTION 'BAPI_NETWORK_COMP_ADD' EXPORTING number = lv_number IMPORTING return = lv_return TABLES i_components_add = lt_components e_message_table = lt_message_table.
二、获取组件列表
lv_number = ls_in-aufnr. CLEAR:lt_components_list[],lv_return. CALL FUNCTION 'BAPI_NETWORK_COMP_GETLIST' EXPORTING number = lv_number * MAX_ROWS = 0 IMPORTING return = lv_return TABLES i_activity_range = lt_activity e_components_list = lt_components_list.
三、获取组件详细信息
lv_number = ls_in-aufnr. "获取详细信息 CLEAR:lv_return,lt_components_detail[]. CALL FUNCTION 'BAPI_NETWORK_COMP_GETDETAIL' EXPORTING number = lv_number * MAX_ROWS = 0 IMPORTING return = lv_return TABLES i_activity_range = lt_activity i_components_id = lt_components_id e_components_detail = lt_components_detail.
四、修改组件信息
"修改组件数量 CALL FUNCTION 'BAPI_PS_INITIALIZATION'. lt_components_change-component = ls_list-component."详细信息BAPI获取到的组件唯一标识 lt_components_change-entry_quantity = lv_syxqsl. lt_components_change-item_text = ls_in-zbz. APPEND lt_components_change. lt_components_change_update-component = ls_list-component. lt_components_change_update-entry_quantity = 'X'. lt_components_change_update-item_text = 'X'. APPEND lt_components_change_update. IF lt_components_change[] IS NOT INITIAL. CLEAR:lv_return,lt_message_table[]. CALL FUNCTION 'BAPI_NETWORK_COMP_CHANGE' EXPORTING number = lv_number IMPORTING return = lv_return TABLES i_components_change = lt_components_change i_components_change_update = lt_components_change_update e_message_table = lt_message_table. CLEAR:lv_message. LOOP AT lt_message_table WHERE message_type CA 'EAX'. lv_check = 'E'. lv_message = lv_message && lt_message_table-message_text. ENDLOOP. ENDIF.
五、移除组件
lt_components_remove-component = ls_list-component."添加到移除内表 APPEND lt_components_remove. IF lt_components_remove[] IS NOT INITIAL. CLEAR:lv_return,lt_message_table[]. CALL FUNCTION 'BAPI_NETWORK_COMP_REMOVE' EXPORTING number = lv_number IMPORTING return = lv_return TABLES i_components_remove = lt_components_remove e_message_table = lt_message_table. ENDIF.
六、同时提交修改和移除BAPI,删除采购申请失败
业务场景中需要保证修改和移除操作同时成功和失败,需要同时COMMIT提交,这就会导致一下情况:
1.先修改后移除,COMMIT,修改成功,移除成功,删除组件对应的采购申请失败
2.先移除后修改,COMMIT,修改失败,移除成功,删除组件对应的采购申请成功
综合考虑,采用第一种方式,对于删除采购申请失败,则调用同步程序RLORD035,同步删除采购申请。
因为该程序修改会弹出文本界面,在接口中会导致接口中断,所以复制为ZRLORD035,将WRITE的文本全部注释,测试满足需求。
REFRESH:s_banfn. LOOP AT lt_eban. s_banfn-sign = 'I'. s_banfn-option = 'EQ'. s_banfn-low = lt_eban-banfn. APPEND s_banfn. ENDLOOP. SUBMIT zrlord035"调用采购申请不符项,将删除数据同步到采购申请,这样采购申请就会被打上删除标识 WITH p_reqs IN s_banfn WITH sim = '' WITH set_del = 'X' AND RETURN.