工单组件更改BAPI
2018.06.02 看见群里有人发的代码。 拷贝下来,修改下~~~~~~
REPORT YTEST_VL02N. TYPES: BEGIN OF TY_OUT, MATNR TYPE MARA-MATNR , MAKTX TYPE MAKT-MAKTX, MAKTX_Z TYPE MAKT-MAKTX, POSNR TYPE RESB-RSPOS, IDNRK TYPE MARA-MATNR, MEINS TYPE MEINS , MENGE TYPE MENGE_D , AUFNR TYPE AFKO-AUFNR, LGORT TYPE MARC-LGPRO, TEXT TYPE CHAR100 , END OF TY_OUT. DATA LT_DATA TYPE STANDARD TABLE OF TY_OUT WITH HEADER LINE . LT_DATA-MATNR = '000000000089006103'. LT_DATA-IDNRK = '000000000029005001'. LT_DATA-POSNR = '0010' . LT_DATA-MEINS = 'KG'. LT_DATA-MENGE = '6000' . LT_DATA-AUFNR = '000010003033'. LT_DATA-LGORT = '1501' . APPEND LT_DATA . DATA L_MSG TYPE STRING. DATA:L_NUMBER LIKE BAPI_NETWORK_LIST-NETWORK, RETURN LIKE BAPIRET2, LI_COMPONENTS_CHANGE LIKE TABLE OF BAPI_NETWORK_COMP_CHANGE, LW_COMPONENTS_CHANGE LIKE BAPI_NETWORK_COMP_CHANGE, LI_COMPONENTS_CHANGE_UPDATE LIKE TABLE OF BAPI_NETWORK_COMP_CNG_UPD, LW_COMPONENTS_CHANGE_UPDATE LIKE BAPI_NETWORK_COMP_CNG_UPD, E_MESSAGE_TABLE LIKE TABLE OF BAPI_METH_MESSAGE, W_MESSAGE_TABLE LIKE BAPI_METH_MESSAGE. DATA:LI_COMPONENTS_DETAIL LIKE TABLE OF BAPI_NETWORK_COMP_DETAIL . DATA:LW_COMPONENTS_DETAIL LIKE BAPI_NETWORK_COMP_DETAIL . LOOP AT LT_DATA . SELECT SINGLE MAKTX INTO LT_DATA-MAKTX FROM MAKT WHERE MATNR = LT_DATA-MATNR . SELECT SINGLE MAKTX INTO LT_DATA-MAKTX_Z FROM MAKT WHERE MATNR = LT_DATA-IDNRK . CLEAR:LI_COMPONENTS_DETAIL,LI_COMPONENTS_DETAIL[],LI_COMPONENTS_CHANGE,LI_COMPONENTS_CHANGE[] ,LI_COMPONENTS_CHANGE_UPDATE,LI_COMPONENTS_CHANGE_UPDATE[],E_MESSAGE_TABLE,E_MESSAGE_TABLE[]. CALL FUNCTION 'BAPI_NETWORK_COMP_GETDETAIL' EXPORTING NUMBER = LT_DATA-AUFNR TABLES E_COMPONENTS_DETAIL = LI_COMPONENTS_DETAIL. LOOP AT LI_COMPONENTS_DETAIL INTO LW_COMPONENTS_DETAIL WHERE ITEM_NUMBER = LT_DATA-POSNR AND MATERIAL = LT_DATA-IDNRK. LW_COMPONENTS_CHANGE-COMPONENT = LW_COMPONENTS_DETAIL-COMPONENT. LW_COMPONENTS_CHANGE-ENTRY_QUANTITY = LT_DATA-MENGE. * lw_components_change-base_uom = lt_data-meins. CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT' EXPORTING INPUT = LT_DATA-MEINS IMPORTING OUTPUT = LW_COMPONENTS_CHANGE-BASE_UOM. LW_COMPONENTS_CHANGE-STGE_LOC = LT_DATA-LGORT. APPEND LW_COMPONENTS_CHANGE TO LI_COMPONENTS_CHANGE . LW_COMPONENTS_CHANGE_UPDATE-COMPONENT = LW_COMPONENTS_DETAIL-COMPONENT. IF LT_DATA-MENGE IS NOT INITIAL . LW_COMPONENTS_CHANGE_UPDATE-ENTRY_QUANTITY = 'X'. ENDIF . IF LT_DATA-MEINS IS NOT INITIAL . LW_COMPONENTS_CHANGE_UPDATE-BASE_UOM = 'X'. ENDIF . IF LT_DATA-LGORT IS NOT INITIAL . LW_COMPONENTS_CHANGE_UPDATE-STGE_LOC = 'X'. ENDIF . APPEND LW_COMPONENTS_CHANGE_UPDATE TO LI_COMPONENTS_CHANGE_UPDATE . CALL FUNCTION 'BAPI_NETWORK_COMP_CHANGE' EXPORTING NUMBER = LT_DATA-AUFNR IMPORTING RETURN = RETURN TABLES I_COMPONENTS_CHANGE = LI_COMPONENTS_CHANGE I_COMPONENTS_CHANGE_UPDATE = LI_COMPONENTS_CHANGE_UPDATE E_MESSAGE_TABLE = E_MESSAGE_TABLE. LOOP AT E_MESSAGE_TABLE INTO W_MESSAGE_TABLE WHERE MESSAGE_TYPE = 'E'. CONCATENATE LT_DATA-AUFNR '-' LT_DATA-MATNR '-' LT_DATA-IDNRK ' bom组件更改失败!' W_MESSAGE_TABLE-MESSAGE_TEXT INTO LT_DATA-TEXT. * lt_data-zicon = '@5C@'. MODIFY LT_DATA. ENDLOOP . IF E_MESSAGE_TABLE[] IS INITIAL . CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING WAIT = 'X'. LT_DATA-TEXT = '更改成功!'. * lt_data-zicon = '@5B@'. MODIFY LT_DATA. ENDIF . CLEAR LW_COMPONENTS_CHANGE. CLEAR LW_COMPONENTS_CHANGE_UPDATE . CLEAR E_MESSAGE_TABLE . CLEAR E_MESSAGE_TABLE[]. ENDLOOP. IF SY-SUBRC <> 0 . CONCATENATE LT_DATA-AUFNR '-' LT_DATA-MATNR '-' LT_DATA-IDNRK ' bom组件更改失败!' '原因:BOM单中未发现该组件!' INTO LT_DATA-TEXT. * lt_data-zicon = '@5C@'. MODIFY LT_DATA. ENDIF . ENDLOOP .