原文链接: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.