Purchase Order' Flexible Workflow - Add Customizing Workflow Start Condition and Dynamic Identify Agent - SAP Blogs
Purchase Order' Flexible Workflow - Add Customizing Workflow Start Condition and Dynamic Identify Agent - SAP Blogs
Community
Product Information
Zhengzhang Lu
June 7, 2020 5 minute read
Hi all,
In my previous blog, I introduced how to run a simple ‘Procure to Pay’ process and ‘Purchase Order’ creation
is one of the main steps. But in real life, we may always use a work ow to control the ‘Purchase Order’
creation process.
In this blog post, I will introduce how to use a exible work ow to control the process in a S/4HANA 1909
system.
As usual, let’s imagine a scenario. There is a trading company and they want to work ow to control their
purchase process. Thye wants the work ow to meet the requirements below.
a. Only the standard Purchase Order should be controlled by the work ow.
b. The work ow start condition should meet all the requirements below.
Company Code
https://blogs.sap.com/2020/06/07/purchase-order-flexible-workflow-add-customizing-workflow-start-condition-and-dynamic-identify-agent/ 1/11
19/05/2021 ‘Purchase Order’ Flexible Workflow: Add Customizing Workflow Start Condition and Dynamic Identify Agent | SAP Blogs
If the ‘Payment Term’ of the ‘Purchase Order’ is payment term1 then employee A should be the agent.
Otherwise, employee B should be the agent.
# Basic Concepts
I will use Fiori App ‘Manage Work ows for Purchase Order‘ to create a exible work ow.
The BADIs below will be used to add the customizing start condition to the work ow.
SWF_PROCESS_WORKFLOW_CONDITION
SWF_WORKFLOW_CONDITION_EVAL
The BADI below will be used to dynamic identity the work ow agent.
MMPUR_WORKFLOW_AGENTS_V2
Before continue reading this blog post, I recommend you read SAP Note 2841783 (How to de ne new Pre-
condition in Manage Work ow for Purchase orders) to have an understanding of the BADIs.
You can use Fiori App ‘Custom Fileds and Logic’ to implement the enhancements or use the GUI
(Transaction Code SE18) to do the enhancements. In this blog post, I will use the GUI way.
As mentioned at the beginning of this blog post, the customizing work ow start condition requirement is:
BADI: SWF_WORKFLOW_CONDITION_DEF
After creating the implementation of the BADI, we should maintain the method ‘GET_CONDITIONS’ in the
implementation class to add the customizing start condition (I will use ‘Test: Material Number’ as the
condition’s name in this blog post).
METHOD if_swf_flex_ifs_condition_def~get_conditions.
ct_condition = VALUE #(
( id = 1 subject = 'Test:Supplier'(001) type = if_swf_flex_ifs_condition_def=>cs_condt
ct_parameter = VALUE #(
( id = 1 name = 'Test:Supplier'(001) xsd_type = if_swf_flex_ifs_condition_def=>cs_x
ENDMETHOD.
https://blogs.sap.com/2020/06/07/purchase-order-flexible-workflow-add-customizing-workflow-start-condition-and-dynamic-identify-agent/ 2/11
19/05/2021 ‘Purchase Order’ Flexible Workflow: Add Customizing Workflow Start Condition and Dynamic Identify Agent | SAP Blogs
After the BADI implementation is activated, the customizing work ow start condition (‘Test: Supplier’) will
appear in the Fiori App ‘Manage Work ows for Purchase Order‘.
BADI: SWF_WORKFLOW_CONDITION_EVAL
After de ned the start condition, we should use this BADI to do the value evaluation of the customizing start
condition.
https://blogs.sap.com/2020/06/07/purchase-order-flexible-workflow-add-customizing-workflow-start-condition-and-dynamic-identify-agent/ 3/11
19/05/2021 ‘Purchase Order’ Flexible Workflow: Add Customizing Workflow Start Condition and Dynamic Identify Agent | SAP Blogs
So at this step, we should verify if the supplier of the ‘Purchase Order’ meets the condition.
METHOD if_swf_flex_ifs_condition_eval~evaluate_condition.
cv_is_true = abap_false.
IF sy-subrc <> 0.
RAISE EXCEPTION TYPE cx_ble_runtime_error
EXPORTING
previous = NEW cx_swf_flex_lra( textid = cx_swf_flex_lra=>object_instance_not_found ).
ENDIF.
CASE is_condition-condition_id.
WHEN 1.
IF lv_custom_field = ls_purchaseorder-supplier.
cv_is_true = abap_true.
ENDIF.
ENDCASE.
ENDMETHOD.
One thing to note, lter (‘Purchase Order’ work ow WS00800238) should be added to the BADI
implementations. Otherwise, other work ows also will trigger the BADIs.
https://blogs.sap.com/2020/06/07/purchase-order-flexible-workflow-add-customizing-workflow-start-condition-and-dynamic-identify-agent/ 4/11
19/05/2021 ‘Purchase Order’ Flexible Workflow: Add Customizing Workflow Start Condition and Dynamic Identify Agent | SAP Blogs
The start condition should consider two parts (supplier and company code).
https://blogs.sap.com/2020/06/07/purchase-order-flexible-workflow-add-customizing-workflow-start-condition-and-dynamic-identify-agent/ 5/11
19/05/2021 ‘Purchase Order’ Flexible Workflow: Add Customizing Workflow Start Condition and Dynamic Identify Agent | SAP Blogs
https://blogs.sap.com/2020/06/07/purchase-order-flexible-workflow-add-customizing-workflow-start-condition-and-dynamic-identify-agent/ 6/11
19/05/2021 ‘Purchase Order’ Flexible Workflow: Add Customizing Workflow Start Condition and Dynamic Identify Agent | SAP Blogs
Let’s check the requirement mentioned at the beginning of this blog post:
‘If the ‘Payment Term’ of the ‘Purchase Order’ is payment term1 then employee A should be the agent.
Otherwise, employee B should be the agent.’
METHOD if_mmpur_workflow_agents_v2~get_approvers.
DATA:
ls_badi_approver TYPE if_mmpur_workflow_agents_v2=>bd_mmpur_s_badi_approver.
IF previousapproverlist IS INITIAL.
SELECT SINGLE * INTO @DATA(ls_purchaseorder)
FROM i_purchaseorderapi01
WHERE purchaseorder = @purchasingdocument.
# Summary
I hope you have a high-level understanding of how to use the exible work ow after reading this blog post.
In my next blog post, I will use a more complex example to go deeper into the main features of the ‘Purchase
Order’ Flexible Work ow.
Best regards,
Jason Lu
Alert Moderator
Assigned tags
https://blogs.sap.com/2020/06/07/purchase-order-flexible-workflow-add-customizing-workflow-start-condition-and-dynamic-identify-agent/ 8/11
19/05/2021 ‘Purchase Order’ Flexible Workflow: Add Customizing Workflow Start Condition and Dynamic Identify Agent | SAP Blogs
Related Questions
6 Comments
Madhu Vadlamani
Hi Jason,
Regards,
Madhu.
Hi Madhu,
The purchase order exible work ow introduced in this blog post is one of the exible work ows in
S/4HANA 1909.
Actually, the exible work ows have been included in the earlier S/4HANA versions (and they are improving
in the versions). You can nd them from the Fiori Library (using 'work ow' as the keyword to search them):
Best regards,
Jason
Madhu Vadlamani
Hi,
i_purchaserequisition_api01
I need API for use roles on table AGR_USER, any idea how to nd it or how to create it?
Utkarsh Rastogi
Hi Zu,
Please suggest.
https://blogs.sap.com/2020/06/07/purchase-order-flexible-workflow-add-customizing-workflow-start-condition-and-dynamic-identify-agent/ 10/11
19/05/2021 ‘Purchase Order’ Flexible Workflow: Add Customizing Workflow Start Condition and Dynamic Identify Agent | SAP Blogs
Ricardo Galicia
Hello All,
Can someone advise how to add a custom message like "Data not possible, please resubmit" in
Thanks,
Ricardo
Add Comment
Find us on
Newsletter Support
https://blogs.sap.com/2020/06/07/purchase-order-flexible-workflow-add-customizing-workflow-start-condition-and-dynamic-identify-agent/ 11/11