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
Advisor
Advisor
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