Enterprise Resource Planning Blogs by SAP
Get insights and updates about cloud ERP and RISE with SAP, SAP S/4HANA and SAP S/4HANA Cloud, and more enterprise management capabilities with SAP blog posts.
cancel
Showing results for 
Search instead for 
Did you mean: 
PANTELIS
Product and Topic Expert
Product and Topic Expert
3,684

Introduction


In this blog post, we will review how to add an additional custom workflow step in purchase orders. This step will resemble an audit-like procedure, meaning it will be triggered every N number of orders. To achieve that, we will be using the following 3 Business Add-Ins (BAdIs):

  1. Providing additional conditions for scenarios - SWF_WORKFLOW_CONDITION_DEF

  2. Value evaluation of additional conditions for scenarios - SWF_WORKFLOW_CONDITION_EVAL

  3. Determination of Workflow Agents for Purchasing Documents - MMPUR_WORKFLOW_AGENTS_V2


 

Providing additional conditions for scenarios


 

Using the Custom Logic app, create a new Enhancement Implementation selecting the following attributes:

  • Business Context: Procurement: Start and Pre-Conditions in Flexible Workflow

  • BAdI Description: Providing additional conditions for scenarios

  • Implementation description: <provide a description for your BAdI> (e.g. WFLW_COND_1)


In the new screen, select the Filter tab and add filter condition, scenario_id = WS00800238.


Figure 1 - SWF_WORKFLOW_CONDITION_DEF filter condition


 

Then, replace the draft logic with the following code.
* condition id - value to be changed
CONSTANTS: audit_N TYPE if_swf_flex_ifs_condition_def=>ty_condition_id VALUE 'CL_SWF_FLEX_IFS_BADI_COND_SAMP' ##NO_TEXT.

ct_condition = VALUE #(
( id = audit_N subject = 'Z_Audit every N orders'(001) type = if_swf_flex_ifs_condition_def=>cs_condtype-start_step )
).

 

Save Draft and Publish.

 

Evaluation of additional conditions


 

After that, create another Enhancement Implementation selecting the following attributes:

  • Business Context: Procurement: Start and Pre-Conditions in Flexible Workflow

  • BAdI Description: Value evaluation of additional conditions for scenarios

  • Implementation description: <provide a description for your BAdI> (e.g. WFLW_EVAL_1)


Similarly to the previous BAdI, select the Filter tab and add filter condition, scenario_id = WS00800238.


Figure 2 - SWF_WORKFLOW_CONDITION_EVAL filter condition


 

Then, replace the draft logic with the following code.
  Data lv_integer type int8.

* condition id - value to be changed
CONSTANTS N_order_audit TYPE if_swf_flex_ifs_condition_def=>ty_condition_id VALUE 'CL_SWF_FLEX_IFS_BADI_COND_SAMP' ##NO_TEXT.

cv_is_true = abap_false.

IF is_condition-condition_id <> N_order_audit.
RAISE EXCEPTION TYPE cx_ble_runtime_error.
ENDIF.

IF is_sap_object_node_type-sont_key_part_1 is not initial.
TRY.
lv_integer = is_sap_object_node_type-sont_key_part_1.
CATCH cx_root INTO DATA(lx_exc) ##CATCH_ALL.
RAISE EXCEPTION TYPE cx_ble_runtime_error
EXPORTING
previous = lx_exc.
ENDTRY.
If lv_integer MOD N eq 0.
cv_is_true = abap_true.
ELSE.
cv_is_true = abap_false.
ENDIF.
ELSE.
cv_is_true = abap_false.
ENDIF.

 

In row 20 (If lv_integer MOD N eq 0) you need to replace N with the frequency number that you would like to have an additional approval step (e.g. 3, 20, 150). Save Draft and Publish.

 

Define the recipient of the additional workflow step


 

Next, create the last Enhancement Implementation selecting the following attributes:

  • Business Context: Procurement: Flexible Workflow

  • BAdI Description: Determination of Workflow Agents for Purchasing Documents

  • Implementation description: <provide a description for your BAdI> (e.g. WFLW_AGENTS_1)


In the new screen, select the Filter tab and add filter condition, scenario_id = PurchaseOrder (similar to Figure 1 above). Then, replace the draft logic with the following code.
    "Code below demonstrates the following: How to use parameter previous approver list,
" How to use whitelisted CDS view I_PurchaseRequisitionApi01 and I_PurchaseRequisitionItemApi01,
" How to differentiate between Procurement Hub and Local scenario using above CDS view.
" How to use step info to determine step level approver
DATA:
ls_badi_approver TYPE if_mmpur_workflow_agents_v2=>bd_mmpur_s_badi_approver,
lt_badi_approver TYPE if_mmpur_workflow_agents_v2=>bd_mmpur_t_badi_approver,
ls_previous_approver TYPE if_mmpur_workflow_agents_v2=>bd_mmpur_s_previous_approver,
ls_new_approver TYPE if_mmpur_workflow_agents_v2=>bd_mmpur_s_badi_approver.

DATA: lv_level TYPE i.

lv_level = lines( previousapproverlist ).

If lv_level eq 1.
ls_badi_approver-businessuser = 'CB9980000000'.
ls_badi_approver-approvallevel = 2.
APPEND ls_badi_approver TO lt_badi_approver.
elseif lv_level eq 0.
ls_badi_approver-businessuser = 'CB9980000000'.
ls_badi_approver-approvallevel = 1.
APPEND ls_badi_approver TO lt_badi_approver.
endif.


** remove the previous approvers from the list of BAdI approvers.
LOOP AT previousapproverlist INTO ls_previous_approver.
READ TABLE lt_badi_approver INTO ls_badi_approver
WITH KEY businessuser = ls_previous_approver-businessuser.
CHECK sy-subrc = 0.
DELETE lt_badi_approver WHERE approvallevel = ls_badi_approver-approvallevel.
ENDLOOP.

** determine the next approval level and appropriate approvers
READ TABLE lt_badi_approver INTO ls_badi_approver INDEX 1.
LOOP AT lt_badi_approver INTO ls_new_approver
WHERE approvallevel = ls_badi_approver-approvallevel.
APPEND ls_new_approver-businessuser TO approverlist.
ENDLOOP.

 

In rows 16 and 20 (ls_badi_approver-businessuser = 'CB9980000000') replace CB9980000000 with the SAP S/4HANA Cloud user ID of the recipient user who will be responsible for the additional approval step (e.g. CB9980000015). Save Draft and Publish.

 

Create the workflow


 

Finally, we will create a simple workflow, where the Purchase Order is automatically approved if the total amount of the order is less than $50 or sent to specific users for approval if the amount is $50 or more. In either case, the Purchase Order will be subject to the audit step (custom workflow).

Open the the Manage Workflows for Purchase Orders app. Select Create and provide a name for your workflow (e.g. PO Workflow with audit). In the Steps section, enter the following steps:

  1. Auto release step

    1. Step Type: Automatic Release of Purchase Order

    2. Step Conditions: Total net amount of purchase order is less than or equal to

    3. Amount: 49.99

    4. Currency: USD



  2. Approval step

    1. Step Type: Release of Purchase Order

    2. Recipients:

      1. Assignment By: User

      2. User: (e.g. CB9980000005, CB9980000009)

      3. Step to be completed by: One of the recipients



    3. Step Conditions: Total net amount of purchase order is greater than

      1. Amount: 49.99

      2. Currency: USD





  3. Audit step

    1. Step name: Z_Audit

    2. Step Type: Release of Purchase Order

    3. Recipients:

      1. Assignment By: Role

      2. Role: Agent Determination by BAdI

      3. Step to be completed by: One of the recipients



    4. Step Conditions: <select the precondition defined in the first BAdI> (e.g. Z_Audit every N orders)




Save and Activate the Workflow.

 

Conclusion


 

Based on the above implementation, below you will find the different approval stages for a Purchase Order:


Figure 3 - Approval details of auto-released Purchase Order not meeting custom precondition



Figure 4 - Approval details of auto-released Purchase Order meeting custom precondition



Figure 5 - Approval details of released for approval Purchase Order not meeting custom precondition



Figure 6 - Approval details of released for approval Purchase Order meeting custom precondition


 

More information regarding the configuration of SAP S/4HANA Cloud Purchase Order workflows can be found in the SAP Help Portal.
4 Comments