SAP Knowledge Base Article - Public

2646400 - BADI - Workflow Agent determination MMPUR_WORKFLOW_AGENTS_V2

Symptom

This KBA introduces some detailed information and the sample code about the BADI  'Workflow Agent determination' (MMPUR_WORKFLOW_AGENTS_V2 ).

* The previous BADI "BADI workflow agents" MM_WORKFLOW_AGENTS is obsolete.

Environment

SAP S/4HANA Cloud Public Edition

SAP S/4HANA Cloud Private Edition

Resolution

This Business Add-In (BAdI) is used in Purchase Order Processing (MM-PUR-PO), Purchase Requisition Processing (MM-PUR-REQ), Purchase Contract (MM-PUR-OA-CON) and Scheduling Agreement Processing (MM-PUR-OA-SCH), RFQ and Quotation Processing (MM-PUR-RFQ), Central Purchase Contract Processing (MM-PUR-HUB-CON), Service Entry Sheet Processing (MM-PUR-SVC-SES) and is intended to be used in a Cloud edition only.

You can use this BAdI to implement your own workflow agent determination. If needed, you can access the purchasing document data. You can access the data by using the corresponding CDS views. Based on the document data, you can define a list of approvers. The import parameter PreviousApproverList provides information about where you are in the workflow and helps you to determine the current approval level and the corresponding approvers.

To differentiate the BAdI implementations, the following filter conditions have to be used:

  • businessobject = PurchaseOrder
  • businessobject = PurchaseRequisition
  • businessobject = CentralPurchaseRequisition
  • businessobject = PurchaseContract
  • businessobject = SchedulingAgreement
  • businessobject = RequestForQuotation
  • businessobject = SupplierQuotation
  • businessobject = CentralPurchaseContract
  • businessobject = ServiceEntrySheet

Requirements

Note Before Implementation

To create a BAdI implementation, you can use the transactions SE18 or SE19, or you can use the Custom Fields and Logic app in the front-end system. If you use the Custom Fields and Logic app, the following applies:

  • The app provides a special ABAP language version ABAP for Key Users. This makes the implementation of BAdIs for business experts and implementation consultants easier.
  • The app ensures that you can use only released interfaces.

If you use the transactions SE19 or SE18 to create a BAdI implementation, the implementation is not visible in the Custom Fields and Logic app.

If several BAdI implementations exist, the system runs through the implementations in the following order:

1. Implementations created in the transactions SE18 or SE19.

2. Implementation created in the Custom Fields and Logic app .

Standard settings

  • In the standard system, the BAdI is not active.
  • The BAdI is filter-independent.
  • With the app Custom Fields and Logic, you can create exactly one active implementation.

Example

Method: GET_APPROVERS

Parameters:

Import Parameters:

The following import parameters are provided:

  • BUSINESSOBJECT                            This parameter provides the business object name (like PurchaseOrder, PurchaseRequisition or SupplierQuotation, etc.)
  • PURCHASINGDOCUMENT               This parameter provides the purchasing document number
  • PURCHASINGDOCUMENTITEM      This parameter provides the item number of purchasing document
  • WORKFLOWSCENARIO                    This parameter provides the information about which workflow scenario is used, as there can be several scenarios for the same business object
  • PREVIOUSAPPROVERLIST            This parameter provides the approvers of the previous approval steps. It is needed to determine the current position in approval workflow. Please note that this list contains only the approvers who have approved the purchase requisition in the previous levels. The approvers corresponding to steps that have been skipped, are not included in this list.

 

  • STEPINFO                                        This parameter provides the current step number and total number of steps in the workflow. The current step number indicates the current level in the approval workflow as defined in the app "Manage Workflows for Purchase Requisitions", for the relevant scenario. For example, consider there are 4 steps in the workflow. If the second step is skipped, and the recipient for the third step is "Agent Determination by BAdI", then the current step level in STEPINFO (field STEPINFO-currentstep) is 3. Please note that STEPINFO is an optional parameter, and is currently available ONLY for the Business Objects, "PurchaseRequisition",“CentralPurchaseRequisition”, "Purchase Order". This parameter is ONLY available from S4HANA 2021 onwards. Lower releases have not this parameter available.

Change Parameter:

  • APPROVERLIST                                This parameter contains the approvers of the current approval level

Example Implementation

lv_level = lines( previousapproverlist ).
**  -----  Approval Level 1
        IF lv_level = 0.
          ls_badi_approver-businessuser = 'CB9980000943'.
          ls_badi_approver-approvallevel = 1.
          APPEND ls_badi_approver TO lt_badi_approver.
*  -----  Approval Level 2
        ELSEIF lv_level = 1.
          ls_badi_approver-businessuser = 'CB9980000945'.
          ls_badi_approver-approvallevel = 2.
          APPEND ls_badi_approver TO lt_badi_approver.
*  -----  Approval Level 3
        ELSEIF lv_level = 2.
          IF ( line_exists( previousapproverlist[ businessuser = 'CB9980000458' ] ) ).
            ls_badi_approver-businessuser = 'CB9980000899'.
            ls_badi_approver-approvallevel = 3.
            APPEND ls_badi_approver TO lt_badi_approver.
          ELSE.
            ls_badi_approver-businessuser = 'CB9980000456'.
            ls_badi_approver-approvallevel = 3.
            APPEND ls_badi_approver TO lt_badi_approver.
          ENDIF.
        ENDIF.

Implementing the above piece of code does the following:

  • The current approval level is determined with the help of the previous approver list
  • Based on the approval level, the current approver is determined
  • If current approval level is 1, approver is set as user 'CB9980000943'
  • If current approval level is 2, approver is set as user 'CB9980000945'
  • If current approval level is 3, the approver is determined based on whether user 'CB9980000458' was one of the previous approvers. If yes, the current approver is set as user 'CB9980000899', else the approver is set as user 'CB9980000456'. 

 

/* This section of code containing "stepinfo" is relevant ONLY for the Business Objects, "PurchaseRequisition" and "CentralPurchaseRequisition" "PurchaseOrder"*/
      IF stepinfo-totalsteps = 2.
        IF stepinfo-currentstep = 1.
          ls_new_approver-businessuser = 'CB9980000943'.
          APPEND ls_new_approver-businessuser TO approverlist.
        ELSEIF stepinfo-currentstep = 2.
          ls_new_approver-businessuser = 'CB9980000658'.
          APPEND ls_new_approver-businessuser TO approverlist.
        ENDIF.
      ELSEIF stepinfo-totalsteps = 3.
        IF stepinfo-currentstep = 1.
          ls_new_approver-businessuser = 'CB9980000783'.
          APPEND ls_new_approver-businessuser TO approverlist.
        ELSEIF stepinfo-currentstep = 2.
          ls_new_approver-businessuser = 'CB9980000568'.
          APPEND ls_new_approver-businessuser TO approverlist.
        ELSEIF stepinfo-currentstep = 3.
          IF ( line_exists( previousapproverlist[ businessuser = 'CB9980000458' ] ) ).
            ls_new_approver-businessuser = 'CB9980000878'.
            APPEND ls_new_approver-businessuser TO approverlist.
          ELSE.
            ls_new_approver-businessuser = 'CB9980000908'.
            APPEND ls_new_approver-businessuser TO approverlist.
          ENDIF.
        ENDIF.
      ENDIF.

 

Implementing the above piece of code does the following:

  • Stepinfo parameter provides the current level in the workflow and the total number of steps in the workflow
  • Based on the total number of steps in the workflow, the approver for the steps 1 and 2 are determined
  • If total number of steps is 2, the approver for step 1 is set as user 'CB9980000943', and the approver for step 2 is set as user 'CB9980000658'.
  • If total number of steps is 3, the approver for step 1 is set as user 'CB9980000783', and the approver for step 2 is set as user 'CB9980000568'. The approver for step 3 is determined based on whether user 'CB9980000458' was one of the previous approvers. If yes, approver for step 3 is set as user 'CB9980000878', else the approver is set as user 'CB9980000908'.

 

 Note: While debugging this Badi ensure you use  the user SAP_WFRT

 

See Also

Please check the attachment of this KBA to find a sample code for this BADI.

Keywords

BAdI, MM_WORKFLOW_AGENTS, STEPINFO , KBA , MM-FIO-PUR-REL , Fiori UI for Purchasing Approval , Problem

Product

SAP S/4HANA Cloud Public Edition all versions

Attachments

BAD_sample_code.txt