项目中,需要对一些采购订单做强制“交货已完成”,如果采购订单已批准,是不能用BAPI_PO_CHANGE更改状态的,只有先除去“批准”状态 ,再“交货已完成”,然后再置为批准状态,下面是函数代码,希望对用到的兄弟有帮助。
DATA:PO_NUMBER LIKE EKKO-EBELN.
DATA:T_POITEM LIKE BAPIMEPOITEM OCCURS 0 WITH HEADER LINE.
DATA:T_POITEMX LIKE BAPIMEPOITEMX OCCURS 0 WITH HEADER LINE.
DATA:T_RETURN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE.
DATA: LV_FRGKE LIKE EKKO-FRGKE,
LV_FRGSX LIKE EKKO-FRGSX.
DATA:RETURN TYPE TABLE OF BAPIRETURN WITH HEADER LINE.
REFRESH OUTPUT.
CLEAR OUTPUT.
SORT INPUT BY EBELN.
LOOP AT INPUT.
CLEAR T_POITEM.
REFRESH T_POITEM.
CLEAR T_POITEMX.
REFRESH T_POITEMX.
MOVE-CORRESPONDING INPUT TO OUTPUT.
CLEAR LV_FRGKE.
SELECT SINGLE
FRGKE
FRGSX
INTO (LV_FRGKE,LV_FRGSX)
FROM EKKO
WHERE EBELN = INPUT-EBELN.
-
如果采购订单被批准了,则先取消批准,才能修改 IF LV_FRGKE = 'R'. CALL FUNCTION 'BAPI_PO_RESET_RELEASE' EXPORTING PURCHASEORDER = INPUT-EBELN PO_REL_CODE = LV_FRGSX USE_EXCEPTIONS = 'X' TABLES RETURN = RETURN. CLEAR RETURN. READ TABLE RETURN WITH KEY TYPE = 'E'. IF SY-SUBRC EQ 0. OUTPUT-FLAG = 'E'. OUTPUT-MESSAGE = RETURN-MESSAGE. ENDIF. ENDIF. IF OUTPUT-FLAG <> 'E'. PO_NUMBER = INPUT-EBELN. T_POITEM-PO_ITEM = INPUT-EBELP. T_POITEM-NO_MORE_GR = 'X'. APPEND T_POITEM. CLEAR T_POITEM. T_POITEMX-PO_ITEM = INPUT-EBELP. T_POITEMX-PO_ITEMX = 'X'. T_POITEMX-NO_MORE_GR = 'X'. APPEND T_POITEMX. CLEAR T_POITEMX. CALL FUNCTION 'BAPI_PO_CHANGE' EXPORTING PURCHASEORDER = PO_NUMBER TABLES RETURN = T_RETURN POITEM = T_POITEM POITEMX = T_POITEMX. READ TABLE T_RETURN WITH KEY TYPE = 'E'. IF SY-SUBRC EQ 0. OUTPUT-FLAG = 'E'. OUTPUT-MESSAGE = T_RETURN-MESSAGE. ROLLBACK WORK. ELSE. OUTPUT-FLAG = 'S'. OUTPUT-MESSAGE = '交货已完成更改成功!'. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING WAIT = 'X'. ENDIF. ENDIF.
-
如果采购订单被批准了,则先取消批准,修改交货已完成后,在重新设置上批准状态 IF LV_FRGKE = 'R' AND OUTPUT-FLAG <> 'E'. CALL FUNCTION 'BAPI_PO_RELEASE' EXPORTING PURCHASEORDER = INPUT-EBELN PO_REL_CODE = LV_FRGSX USE_EXCEPTIONS = 'X' TABLES RETURN = RETURN. ENDIF. APPEND OUTPUT. CLEAR OUTPUT.
ENDLOOP.