採購訂單的審批、撤回審批及拒絕 ME29N

ll的个人笔记發表於2024-09-05

原文連結:https://blog.csdn.net/z_x_xing_/article/details/90201003

前臺操作,如下圖:

點選圖中的批准按鈕,逐級完成採購訂單的審批節點。

2.檢視錶中資料

釋出狀態——對應前臺介面當前已審批的節點

BAPI使用

CALL FUNCTION 'BAPI_PO_RELEASE'
EXPORTING
PURCHASEORDER = '4100000163' "對應採購訂單編號
PO_REL_CODE = 'A1' "對應前臺審批節點(A1,A2,A3)
TABLES
RETURN = LT_RETURN "返回訊息
EXCEPTIONS
AUTHORITY_CHECK_FAIL = 1
DOCUMENT_NOT_FOUND = 2
ENQUEUE_FAIL = 3
PREREQUISITE_FAIL = 4
RELEASE_ALREADY_POSTED = 5
RESPONSIBILITY_FAIL = 6
OTHERS = 7.
IF SY-SUBRC <> 0.
"報錯
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
INTO DATA(MTEXT)
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
EXIT.
ELSE.
"校驗返回訊息表資訊
LOOP AT LT_RETURN INTO LW_RETURN WHERE TYPE = 'A' OR TYPE = 'E'.
"報錯
WRITE:/ LW_RETURN-MESSAGE.
EXIT.
ENDLOOP.
"成功
IF SY-SUBRC NE 0.
WRITE:/ '成功'.
ENDIF.

ENDIF.

採購訂單取消審批

前臺操作,如下圖:

未取消審批前

點選“撤回”按鈕,撤回採購訂單審批

BAPI使用:

CALL FUNCTION 'BAPI_PO_RESET_RELEASE'
EXPORTING
PURCHASEORDER = '4100000163' "對應採購訂單單號
PO_REL_CODE = 'A1' "撤銷到的節點
TABLES
RETURN = LT_RETURN "返回訊息
EXCEPTIONS
AUTHORITY_CHECK_FAIL = 1
DOCUMENT_NOT_FOUND = 2
ENQUEUE_FAIL = 3
PREREQUISITE_FAIL = 4
RELEASE_ALREADY_POSTED = 5
RESPONSIBILITY_FAIL = 6
NO_RELEASE_ALREADY = 7
NO_NEW_RELEASE_INDICATOR = 8
OTHERS = 9.
IF SY-SUBRC <> 0.
"報錯
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
INTO DATA(MTEXT1)
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
EXIT.
ELSE.
"校驗返回訊息表資訊
LOOP AT LT_RETURN INTO LW_RETURN WHERE TYPE = 'A' OR TYPE = 'E'.
"報錯
WRITE:/ LW_RETURN-MESSAGE.
EXIT.
ENDLOOP.
"成功
IF SY-SUBRC NE 0.
WRITE:/ '成功'.
ENDIF.
ENDIF.

拒絕採購訂單審批

前臺操作,如下圖:

點選“拒絕”按鈕,完成採購訂單拒絕操作。

程式碼實現:

DATA LC_PO TYPE REF TO CL_PO_HEADER_HANDLE_MM.
DATA LS_DOCUMENT TYPE MEPO_DOCUMENT.
DATA LV_EBELN TYPE EKKO-EBELN.

* prepare creation of PO instance
LS_DOCUMENT-DOC_TYPE = 'F'. "預設值,表示採購憑證-採購訂單
LS_DOCUMENT-PROCESS = MMPUR_PO_PROCESS. "預設值
LS_DOCUMENT-TRTYP = 'V'. "預設值,表示更改
LS_DOCUMENT-DOC_KEY(10) = '4100000163'. "PO單號
LS_DOCUMENT-INITIATOR-INITIATOR = MMPUR_INITIATOR_REL.

* object creation and initialization
LV_EBELN = '4100000163'. "PO單號
CREATE OBJECT LC_PO.
LC_PO->FOR_BAPI = MMPUR_YES.
CALL METHOD LC_PO->PO_INITIALIZE( IM_DOCUMENT = LS_DOCUMENT ). "初始化採購憑證
CALL METHOD LC_PO->SET_PO_NUMBER( IM_PO_NUMBER = LV_EBELN ). "賦值採購訂單單號
CALL METHOD LC_PO->SET_STATE( CL_PO_HEADER_HANDLE_MM=>C_AVAILABLE ). "設定採購訂單狀態

* read purchase order from database
CALL METHOD LC_PO->PO_READ
EXPORTING
IM_TCODE = 'ME29N' "事務程式碼
IM_TRTYP = LS_DOCUMENT-TRTYP "事務型別
IM_AKTYP = LS_DOCUMENT-TRTYP
IM_PO_NUMBER = LV_EBELN "採購訂單單號
IM_DOCUMENT = LS_DOCUMENT. "文件型別

"校驗當前採購訂單狀態是否可以發起拒絕
IF LC_PO->IF_RELEASABLE_MM~IS_REJECTION_ALLOWED( ) = 'X'.
"拒絕當前採購訂單
CALL METHOD LC_PO->IF_RELEASABLE_MM~REJECT
EXPORTING
IM_RESET = SPACE
EXCEPTIONS
FAILED = 1
OTHERS = 2.

WRITE:/ '成功'.
ELSE.
"否則報錯
WRITE:/ '失敗'.

ENDIF.

"提交
CALL METHOD LC_PO->PO_POST
EXCEPTIONS
FAILURE = 1
OTHERS = 2.

相關文章