Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

19/05/2021 ‘Purchase Order’ Flexible Workflow: Add Customizing Workflow Start Condition and Dynamic Identify Agent | SAP

fy Agent | SAP Blogs

Community

Ask a Question Write a Blog Post

Product Information

Zhengzhang Lu
June 7, 2020 5 minute read

‘Purchase Order’ Flexible Work ow: Add Customizing


Work ow Start Condition and Dynamic Identify Agent
Follow RSS feed Like

2 Likes 2,115 Views 6 Comments

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.

The work ow start conditions are:

Company Code

The supplier of the ‘Purchase Order’ is ‘Sup1’

c. The work ow agent should be dynamic decided.

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

I will introduce how to use the BADIs in this blog post.

# Maintain Customizing Work ow Start Condition


As mentioned in this blog post, BADIs SWF_WORKFLOW_CONDITION_DEF and
SWF_WORKFLOW_CONDITION_EVAL will be used to achieve this requirement.

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:

‘The supplier of the ‘Purchase Order’ is ‘Sup1’

We can achieve this requirement in two steps.

Step 1: Add customizing work ow start condition

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).

The code used in my test:

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‘.

Step 2: Value evaluation of the customizing work ow start condition

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

Let’s come back to the requirement:

‘The supplier of the ‘Purchase Order’ is ‘Sup1’

So at this step, we should verify if the supplier of the ‘Purchase Order’ meets the condition.

The sample code in my test:

METHOD if_swf_flex_ifs_condition_eval~evaluate_condition.

data: lv_custom_field type string.


IF ( is_condition-condition_id > 1 ).
RAISE EXCEPTION TYPE cx_ble_runtime_error
EXPORTING
previous = NEW cx_swf_flex_lra( textid = cx_swf_flex_lra=>condition_not_supported ).
ENDIF.

cv_is_true = abap_false.

SELECT SINGLE * INTO @DATA(ls_purchaseorder)


FROM i_purchaseorderapi01
WHERE purchaseorder = @is_sap_object_node_type-sont_key_part_1.

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.

READ TABLE it_parameter_value INTO DATA(ls_param_value) WITH KEY name = 'Test:Supplier'.


IF sy-subrc EQ 0.
lv_custom_field = ls_param_value-value.
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

# Create A Flexible Work ow For Purchase Order


The detailed information of Fiori App ‘Manage Work ows for Purchase Order‘ can be found from the Fiori
Apps Library.

https:// oriappslibrary.hana.ondemand.com/sap/ x/externalViewer/#/detail/Apps(‘F2872’)/S16OP

Step 1: Add a new work ow.

Step 2: Maintain ‘Work ow Name’ and ‘Start Conditions’.

We should maintain the work ow name and the start condition.

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

Step 3: Add ‘Step Sequence’

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

‘Release of Purchase Order’ is selected as the ‘Step Type’.

I will use BADI to dynamic determines the agent.

# Dynamic Determine Work ow Agent


As introduced, BADI ‘MMPUR_WORKFLOW_AGENTS_V2‘ can be used to help us dynamic determine the
work ow agent. To better understand this BADI, I recommend you read SAP Note 2646400 (BADI –
Work ow Agent determination MMPUR_WORKFLOW_AGENTS_V2) before continue read this blog post.

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.’

We should maintain the logic in the method ‘IF_MMPUR_WORKFLOW_AGENTS_V2~GET_APPROVERS’ of


the BADI implementation class to archive this requirement.
https://blogs.sap.com/2020/06/07/purchase-order-flexible-workflow-add-customizing-workflow-start-condition-and-dynamic-identify-agent/ 7/11
19/05/2021 ‘Purchase Order’ Flexible Workflow: Add Customizing Workflow Start Condition and Dynamic Identify Agent | SAP Blogs

The code used in my test:

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.

IF ls_purchaseorder IS NOT INITIAL.


IF ls_purchaseorder-paymentterms = 'PT1'.
ls_badi_approver-businessuser = 'EMP1'.
ELSE.
ls_badi_approver-businessuser = 'EMP2'.
ENDIF.
APPEND ls_badi_approver TO approverlist.
ENDIF.
ENDMETHOD.

# 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

SAP S/4HANA | #FlexibleWork ow | Flexible work ow |

Related Blog Posts

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

Flexible Work ow for Sourcing and Procurement in SAP S/4HANA


By Chelliah Soundar , Aug 25, 2020

Flexible Work ow Steps


By Ruthvik Chowdary , Dec 26, 2019

Lean Service Procurement in SAP S/4HANA


By Kumar Chockalingam , Oct 21, 2020

Related Questions

Flexible work ow not triggered for Purchase Requisition


By Sher Lynn Teh , Apr 07, 2020
Trying to Trigger Flexible work ow with Custom FM
By shaikzainulla Buddin , Jan 14, 2021

PO release strategy (with class multi level) to exible work ow in S4 1709?


By Team ABAP , Sep 28, 2018

6 Comments

Madhu Vadlamani

June 9, 2020 at 3:45 pm

Hi Jason,

Hana 1909 is having exible work ows. Is this similar to that .

Regards,

Madhu.

Like (0) | Reply | Alert Moderator

Zhengzhang Lu | Post author

June 9, 2020 at 5:11 pm

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):

https:// oriappslibrary.hana.ondemand.com/sap/ x/externalViewer/#/home


https://blogs.sap.com/2020/06/07/purchase-order-flexible-workflow-add-customizing-workflow-start-condition-and-dynamic-identify-agent/ 9/11
19/05/2021 ‘Purchase Order’ Flexible Workflow: Add Customizing Workflow Start Condition and Dynamic Identify Agent | SAP Blogs

Best regards,

Jason

Like (0) | Reply | Alert Moderator

Madhu Vadlamani

June 10, 2020 at 4:06 am

Thank You. I will look into this.

Like (0) | Reply | Alert Moderator

Gaurav Kashinath Pednekar

September 30, 2020 at 11:19 am

Hi,

In this you are using below API which is already available.

i_purchaserequisition_api01

I need API for use roles on table AGR_USER, any idea how to nd it or how to create it?

Like (0) | Reply | Alert Moderator

Utkarsh Rastogi

January 12, 2021 at 2:59 pm

Hi Zu,

Inside the method of SWF_WORKFLOW_CONDITION_EVAL-EVALUATE_CONDITION - We are not getting the


PO number which is supposed to be part of importing parameter (is_sap_object_node_type-
sont_key_part_1).

Please suggest.

Like (0) | Reply | Alert Moderator

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

February 1, 2021 at 10:33 am

Hello All,

Can someone advise how to add a custom message like "Data not possible, please resubmit" in

RAISE EXCEPTION TYPE cx_ble_runtime_error.

Thanks,

Ricardo

Like (0) | Reply | Alert Moderator

Add Comment

Find us on

Privacy Terms of Use

Legal Disclosure Copyright

Trademark Preferências de Cookies

Newsletter Support

https://blogs.sap.com/2020/06/07/purchase-order-flexible-workflow-add-customizing-workflow-start-condition-and-dynamic-identify-agent/ 11/11

You might also like