Wednesday 10 June 2020

S/4 Purchase Order Flexible Workflow: Agent Determination by BADI

As you know, in S/4 we have the Flexible Workflows scenarios. In some business cases, the standard agent determinations is not enough to meet the company’s needs, so we need to add custom code to make it 100%. On the Agent determination side, we have BADIs to accomplish that. Here, i’m gonna show how to use the Agent Determination BADI on the Purchase Order approval Flexible Scenario.

ABAP Development, S/4HANA, SAP ABAP Tutorial and Material, SAP ABAP Exam Prep

The Purchase Order approval Flexible Scenario (SWDD_SCENARIO) is: WS00800238:

ABAP Development, S/4HANA, SAP ABAP Tutorial and Material, SAP ABAP Exam Prep

If you select the flexible process:

ABAP Development, S/4HANA, SAP ABAP Tutorial and Material, SAP ABAP Exam Prep

In the Agent Rules tab, you see all the available options that the user can select when configuring the Flexible Scenario:

ABAP Development, S/4HANA, SAP ABAP Tutorial and Material, SAP ABAP Exam Prep

On the FIORI App:

ABAP Development, S/4HANA, SAP ABAP Tutorial and Material, SAP ABAP Exam Prep

ABAP Development, S/4HANA, SAP ABAP Tutorial and Material, SAP ABAP Exam Prep

If you select the BADIAgentDetermination, you’ll see that it uses the 00800036 Rule (PFAC):

ABAP Development, S/4HANA, SAP ABAP Tutorial and Material, SAP ABAP Exam Prep

And in there, it calls the FM MMPUR_WFL_PO_BADI_AGENTS:

ABAP Development, S/4HANA, SAP ABAP Tutorial and Material, SAP ABAP Exam Prep

Cool, so now we now the how it get’s done. But now, i want to insert my Custom Code on the process:

ABAP Development, S/4HANA, SAP ABAP Tutorial and Material, SAP ABAP Exam Prep

For that we need to implement BADI MMPUR_WORKFLOW_AGENTS_V2.

When you implement it, it even gives you the choice to copy the sample class:

ABAP Development, S/4HANA, SAP ABAP Tutorial and Material, SAP ABAP Exam Prep

After the correct implementation:

ABAP Development, S/4HANA, SAP ABAP Tutorial and Material, SAP ABAP Exam Prep

The GET_APPROVERS method is where our logic will be:

ABAP Development, S/4HANA, SAP ABAP Tutorial and Material, SAP ABAP Exam Prep

Inserted some sample code:

ABAP Development, S/4HANA, SAP ABAP Tutorial and Material, SAP ABAP Exam Prep

Here it is:

  METHOD IF_MMPUR_WORKFLOW_AGENTS_V2~GET_APPROVERS.
    DATA:
      LS_BADI_APPROVER TYPE IF_MMPUR_WORKFLOW_AGENTS_V2=>BD_MMPUR_S_BADI_APPROVER.
** DEMO
    IF PURCHASINGDOCUMENT EQ '0010203040'.
      LS_BADI_APPROVER-BUSINESSUSER = 'WF-BATCH'."Sample user here, could be anyone...
      LS_BADI_APPROVER-APPROVALLEVEL = 1.
      APPEND LS_BADI_APPROVER TO APPROVERLIST.
    ENDIF.
  ENDMETHOD.

So now, testing the rule (in PFAC) by passing the 10203040 PO, i’m getting the user as the Agent. Now, he would be getting the Workflows for approval, if the BADI Agent Determination is selected in any Flexible Workflow process for Purchase Order.

ABAP Development, S/4HANA, SAP ABAP Tutorial and Material, SAP ABAP Exam Prep

No comments:

Post a Comment