ABAP:ME22N采购订单修改BAPI
ME22N采购订单修改BAPI:
FUNCTION zsdfu015. *"---------------------------------------------------------------------- *"*"本地接口: *" IMPORTING *" VALUE(I_ID) TYPE ZRFC_LOGID OPTIONAL *" VALUE(I_CANUM) TYPE CANUM OPTIONAL *" EXPORTING *" VALUE(E_CODE) TYPE MSGTY *" VALUE(E_MSG) TYPE MSGTXT *" VALUE(E_FLOW_END) TYPE CHAR01 *" TABLES *" ET_RETURN STRUCTURE ZRFCT005 OPTIONAL *"---------------------------------------------------------------------- DATA:ls_zsdt024 TYPE zsdt024, lt_zsdt024 TYPE TABLE OF zsdt024, ls_zsdt008 TYPE zsdt008, lt_zsdt008 TYPE TABLE OF zsdt008, ls_zrfct002 TYPE zrfct002, ls_zrfct005 TYPE zrfct005. "获取源表数据 CLEAR:lt_zsdt024. SELECT * INTO CORRESPONDING FIELDS OF TABLE lt_zsdt024 FROM zsdt024 WHERE zrfc_logid = i_id. IF lt_zsdt024 IS INITIAL. e_code = 'E'. e_msg = '无可执行数据'. RETURN. ENDIF. "采购订单修改BAPI结构定义 DATA:purchaseorder TYPE bapimepoheader-po_number, return LIKE TABLE OF bapiret2 WITH HEADER LINE, poitem LIKE TABLE OF bapimepoitem WITH HEADER LINE, poitemx LIKE TABLE OF bapimepoitemx WITH HEADER LINE, pocond LIKE TABLE OF bapimepocond WITH HEADER LINE, pocondx LIKE TABLE OF bapimepocondx WITH HEADER LINE, poschedule LIKE TABLE OF bapimeposchedule WITH HEADER LINE, poschedulex LIKE TABLE OF bapimeposchedulx WITH HEADER LINE. CLEAR:purchaseorder, return[], return, poitem, poitem[], poitemx, poitemx[], pocond, pocond[], pocondx, pocondx[]. DATA:lv_mtart TYPE mara-mtart. LOOP AT lt_zsdt024 INTO ls_zsdt024. AT END OF ebeln. purchaseorder = ls_zsdt024-ebeln. ENDAT. IF ls_zsdt024-zbs = 'U'."修改 poitem-po_item = ls_zsdt024-ebelp. poitemx-po_item = ls_zsdt024-ebelp. poitemx-po_itemx = 'X'. APPEND: poitemx,poitem. CLEAR: poitem, poitemx. poschedule-po_item = ls_zsdt024-ebelp."行项目 poschedulex-po_item = ls_zsdt024-ebelp. poschedule-sched_line = '0001'. poschedulex-sched_line = '0001'. poschedule-delivery_date = ls_zsdt024-eindt. "交货日期 poschedulex-delivery_date = 'X'. poschedule-quantity = ls_zsdt024-menge."数量 poschedulex-quantity = 'X'. APPEND:poschedule,poschedulex. CLEAR:poschedule,poschedulex. pocond-itm_number = ls_zsdt024-ebelp. pocond-change_id = 'U'. APPEND pocond. pocondx-itm_number = ls_zsdt024-ebelp. pocondx-itm_numberx = 'X'. pocond-change_id = 'X'. APPEND pocondx. CLEAR:pocond,pocondx. ELSEIF ls_zsdt024-zbs = 'I'."新增 "行项目 poitem-po_item = ls_zsdt024-ebelp. poitemx-po_item = ls_zsdt024-ebelp. poitemx-po_itemx = 'X'. poitem-material = ls_zsdt024-matnr."物料 poitemx-material = 'X'. poitem-quantity = ls_zsdt024-menge."数量 poitemx-quantity = 'X'. poitem-plant = ls_zsdt024-werks."工厂 poitemx-plant = 'X'. * IF LS_ZSDT024-WERKS = '7888'. * SELECT SINGLE LGFSB INTO POITEM-STGE_LOC FROM MARC WHERE MATNR = LS_ZSDT024-MATNR AND WERKS = LS_ZSDT024-WERKS. * ELSE. * CLEAR:LV_MTART. * SELECT SINGLE MTART INTO LV_MTART FROM MARA WHERE MATNR = LS_ZSDT024-MATNR. * SELECT SINGLE LGORT INTO POITEM-STGE_LOC FROM ZSDT003 WHERE MTART = LV_MTART AND WERKS = LS_ZSDT024-WERKS. * ENDIF. poitemx-stge_loc = 'X'. SELECT SINGLE meins INTO poitem-po_unit FROM mara WHERE matnr = ls_zsdt024-matnr. poitemx-po_unit = 'X'. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTING input = ls_zsdt024-banfn IMPORTING output = ls_zsdt024-banfn. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTING input = ls_zsdt024-bnfpo IMPORTING output = ls_zsdt024-bnfpo. poitem-preq_no = ls_zsdt024-banfn."采购申请 poitemx-preq_no = 'X'. poitem-preq_item = ls_zsdt024-bnfpo."采购申请项目 poitemx-preq_item = 'X'. SELECT SINGLE infnr INTO poitem-info_rec FROM eina WHERE matnr = ls_zsdt024-matnr AND lifnr = ls_zsdt024-lifnr AND loekz <> 'X' . poitemx-info_rec = 'X'. poitem-tax_code = ls_zsdt024-mwskz. " 税码 poitemx-tax_code = 'X'. poitem-no_rounding = 'X'. poitemx-no_rounding = 'X'. APPEND poitemx. APPEND poitem. CLEAR: poitem, poitemx. poschedule-po_item = ls_zsdt024-ebelp."行项目 poschedulex-po_item = ls_zsdt024-ebelp. poschedule-del_datcat_ext = 'D'. "交货日期的类别 poschedulex-del_datcat_ext = 'X'. poschedule-delivery_date = sy-datum. poschedulex-delivery_date = 'X'. poschedule-quantity = ls_zsdt024-menge."数量 poschedulex-quantity = 'X'. APPEND:poschedule,poschedulex. CLEAR:poschedule,poschedulex. pocond-itm_number = ls_zsdt024-ebelp. pocond-cond_type = 'PB00'. " Give the pricing condition type that derives netprice pocond-cond_value = ls_zsdt024-brtwr. pocond-currency = ls_zsdt024-koein. pocond-cond_p_unt = ls_zsdt024-kpein. pocond-change_id = 'I'. pocondx-itm_number = ls_zsdt024-ebelp. pocondx-itm_numberx = 'X'. pocondx-cond_type = 'X'. pocondx-cond_value = 'X'. pocondx-currency = 'X'. pocondx-cond_p_unt = 'X'. pocondx-change_id = 'X'. APPEND:pocondx,pocond. ELSEIF ls_zsdt024-zbs = 'D'."删除 poitem-po_item = ls_zsdt024-ebelp. poitemx-po_item = ls_zsdt024-ebelp. poitemx-po_itemx = 'X'. poitem-delete_ind = 'X'. "采购订单行项目删除标识 poitemx-delete_ind = 'X'. APPEND: poitemx,poitem. CLEAR: poitem, poitemx. ENDIF. CLEAR:ls_zsdt024. ENDLOOP. CALL FUNCTION 'BAPI_PO_CHANGE' EXPORTING purchaseorder = purchaseorder no_price_from_po = 'X' TABLES poitem = poitem poitemx = poitemx poschedule = poschedule poschedulex = poschedulex * POACCOUNT = LT_POACCOUNT * POACCOUNTX = LT_POACCOUNTX * POSERVICES = IT_SERVICE * POSRVACCESSVALUES = LT_POSRVACCESSVALUES pocond = pocond pocondx = pocondx return = return. LOOP AT return WHERE type = 'E' OR type = 'A' OR type = 'X'. CONCATENATE e_msg return-message INTO e_msg SEPARATED BY '/'. ENDLOOP. IF sy-subrc NE 0. CALL METHOD zcl_rfc=>get_source EXPORTING i_id = i_id i_canum = i_canum IMPORTING e_zrfct002 = ls_zrfct002. * RECEIVING * R_SOURCE = LS_SOURCE. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X'. CLEAR:ls_zsdt008. ls_zsdt008-canum = ls_zrfct002-canum. ls_zsdt008-objtype = ls_zrfct002-objtype_save. ls_zsdt008-objkey = purchaseorder. ls_zsdt008-zrfcid = ls_zrfct002-zrfcid. ls_zsdt008-zrfc_logid = i_id. APPEND ls_zsdt008 TO lt_zsdt008. MODIFY zsdt008 FROM TABLE lt_zsdt008. e_code = 'S'. CONCATENATE 'PO:' purchaseorder '修改成功' INTO e_msg. CLEAR:ls_zrfct005. ls_zrfct005-status = '53'. ls_zrfct005-msgty = e_code. ls_zrfct005-msgid = '00'. ls_zrfct005-msgno = '001'. ls_zrfct005-msgv1 = e_msg. ls_zrfct005-msgv4 = purchaseorder. APPEND ls_zrfct005 TO et_return. ELSE. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. e_code = 'E'. ENDIF. ENDFUNCTION.