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: 
JasonLu
Product and Topic Expert
Product and Topic Expert
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 workflow to control the 'Purchase Order' creation process.

In this blog post, I will introduce how to use a flexible workflow 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 workflow to control their purchase process. Thye wants the workflow to meet the requirements below.

a. Only the standard Purchase Order should be controlled by the workflow.

b. The workflow start condition should meet all the requirements below.

The workflow start conditions are:

Company Code

The supplier of the 'Purchase Order' is 'Sup1'

c. The workflow agent should be dynamic decided.

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 Workflows for Purchase Order' to create a flexible workflow.

The BADIs below will be used to add the customizing start condition to the workflow.

SWF_PROCESS_WORKFLOW_CONDITION

SWF_WORKFLOW_CONDITION_EVAL

The BADI below will be used to dynamic identity the workflow agent.

MMPUR_WORKFLOW_AGENTS_V2

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

# Maintain Customizing Workflow 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 define new Pre-condition in Manage Workflow 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 workflow start condition requirement is:

'The supplier of the 'Purchase Order' is 'Sup1'

We can achieve this requirement in two steps.

Step 1: Add customizing workflow 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_condtype-start_step ) ).
ct_parameter = VALUE #(
( id = 1 name = 'Test:Supplier'(001) xsd_type = if_swf_flex_ifs_condition_def=>cs_xstype-string mandatory = abap_true ) ).

ENDMETHOD.

After the BADI implementation is activated, the customizing workflow start condition ('Test: Supplier') will appear in the Fiori App 'Manage Workflows for Purchase Order'.


Step 2: Value evaluation of the customizing workflow start condition

BADI: SWF_WORKFLOW_CONDITION_EVAL

After defined the start condition, we should use this BADI to do the value evaluation of the customizing start condition.

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, filter ('Purchase Order' workflow WS00800238) should be added to the BADI implementations. Otherwise, other workflows also will trigger the BADIs.



# Create A Flexible Workflow For Purchase Order


The detailed information of Fiori App 'Manage Workflows for Purchase Order' can be found from the Fiori Apps Library.

https://fioriappslibrary.hana.ondemand.com/sap/fix/externalViewer/#/detail/Apps('F2872')/S16OP

Step 1: Add a new workflow.


Step 2: Maintain 'Workflow Name' and 'Start Conditions'.

We should maintain the workflow name and the start condition.

The start condition should consider two parts (supplier and company code).


Step 3: Add 'Step Sequence'


'Release of Purchase Order' is selected as the 'Step Type'.


I will use BADI to dynamic determines the agent.



# Dynamic Determine Workflow Agent


As introduced, BADI 'MMPUR_WORKFLOW_AGENTS_V2' can be used to help us dynamic determine the workflow agent. To better understand this BADI, I recommend you read SAP Note 2646400 (BADI - Workflow 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.

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 flexible workflow 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 Workflow.

Best regards,

Jason Lu

 
14 Comments
madhu_vadlamani
Active Contributor
0 Kudos
Hi Jason,

Hana 1909 is having flexible workflows. Is this similar to that .

 

Regards,

Madhu.
JasonLu
Product and Topic Expert
Product and Topic Expert
0 Kudos
Hi Madhu,

The purchase order flexible workflow introduced in this blog post is one of the flexible workflows in S/4HANA 1909.

Actually, the flexible workflows have been included in the earlier S/4HANA versions (and they are improving in the versions). You can find them from the Fiori Library (using 'workflow' as the keyword to search them):

https://fioriappslibrary.hana.ondemand.com/sap/fix/externalViewer/#/home

Best regards,

Jason

 
madhu_vadlamani
Active Contributor
0 Kudos
Thank You. I will look into this.
0 Kudos
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 find it or how to create it?
Utkarsh
Participant
0 Kudos
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.
former_member725503
Discoverer
0 Kudos
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
prabhatpathani
Explorer
Hey Utkarsh,

The method gets called multiple calls, in the initial call the importing parameter is empty, in the follow-on calls the parameter is filled.
Utkarsh
Participant
0 Kudos
Thanks prabhatpathania01 . We solved it the same way.
0 Kudos
Hello Utkarsh,

How did you resolve the problem?

I am facing the same problem.

Thanks & Regards,

Soham Zendekar
Utkarsh
Participant
0 Kudos
Hi Soham,

The BADI gets triggered twice. You will notice that the data is populated in the importing parameters the second time.
K_A_Hasan
Discoverer
0 Kudos
Did you slove the problem?

I am facing the same issue.How can we get the values of the condition?
0 Kudos
Hi All,

Hope all is well.

I am new to workflow.

Need your advice on how to trigger debug on the method EVALUATE_CONDITION. I try to put my own session breakpoint and also external Breakpoint as WF-BATCH.

 

Appreciate your help.

Thanks.
JasonLu
Product and Topic Expert
Product and Topic Expert
WF-BATCH has been replaced with user SAP_WFRT in S/4HANA.
0 Kudos
Thank for the reply.

I have change the user to SAP_WFRT and it is still not trigger the breakpoint.

Do you have any idea on how can I trigger the breakpoint?

My situation is currently I am using this BADI for Supplier Invoice workflow.

I have added the condition and the condition is appear only Manage workflow for Supplier Invoice App.

But when I try to post an invoice, it does not stop at the breakpoint of the method.

BTW I am copying the example class to see how I can leverage on this BADI.