Skip to Content
Technical Articles
Author's profile photo Gaurav Jain

SAP S/4HANA Cloud – Flexible Workflow with new custom Pre-Condition for Purchase Requisition

Introduction

In this blog post you will learn how to add Custom Pre-Conditions to build a flexible workflow for purchase requisition in SAP S/4HANA Cloud. To know more about Flexible workflow read this blog post https://blogs.sap.com/2019/10/21/s4hana-flexible-workflows-workflow-scenario-development-and-configuration/

Environment

From: – S4HC 1902, SAP S/4HANA 1909

Flexible Workflow for Purchase Requisition

Use

In this use case, I am adding custom pre-condition in workflow at item level for purchase requisition, so once you create Purchase Requisition and click on save, workflow will get triggered and will be sent for approval at Item Level.

I have created purchase requisition with “Supplier Material Number” and defined custom pre-condition for this supplier material number in workflow. If the value of supplier material number matches with defined pre-condition, then workflow will get triggered.

Reproducing the Issue

SAP has delivered a set of pre-conditions and step conditions. We can additionally define our own pre-condition / step condition using the custom BADI.

Before Implementation of BADI for custom Pre-Condition, below are list of some standard pre-conditions in purchase requisition.

Once BADI’s are implemented, then those pre-condition / step condition will be visible in above list of  Manage Workflows for purchase requisition app for the respective filter criteria.

We need to evaluate the defined pre-condition / step condition against the newly created BO using BADI.

Both  BADI’s needs to be implemented in order to define and evaluate new custom pre-condition / step condition

Filter Conditions would be the scenario ID. The following are some of the scenario ID’s  that can be used:

  1. WS00800157 – Release of Purchase Requisition Header Level
  2. WS00800173 – Release of Purchase Requisition Item Level
  3. WS02000434 – Release of Central PR Header Level
  4. WS02000438 – Release of Central PR Item Level
  5. WS02000458-  Release of Purchase Requisition for header level using the APP Manage Workflow for Purchase Requisitions – New
  6. WS02000471-  Release of Purchase Requisition for item level using the APP Manage Workflow for Purchase Requisitions – New
  7. WS00800251-  Workflow for blocked invoices
  8. WS00800303 – Workflow for parked invoices as complete
  9. WS00800238 – Workflow for Purchase Orders.

#Step 1 :-

BAdI’s Implementation

  1. New pre conditions can be defined using custom BADI SWF_WORKFLOW_CONDITION_DEF.
  2. Defined pre-condition / step condition needs to be evaluated using BADI SWF_WORKFLOW_CONDITION_EVAL

Go to App “Custom Fields and Logic”->Custom Logic.

Go to Top right corner of this APP and click on “+” for creating new BADI Implementation.

 

It will ask for New Implementation Details

Business Context: Start and Pre-Condition in Flexible Workflow.

BAdI Description: Providing additional conditions for scenario.

New BADI has been created, go to documentation tab and read implementation usage.

We need to define filter condition based upon scenario id, so the precondition will only be visible to that scenario.

Go to filter tab and give scenario id, list of scenario id is mentioned above.

Scenario Id for Release of purchase Requisition Item is WS02000471.

Some Sample Code for understanding

ID  : Unique ID, Subject  : Name of Additional Condition, Type : Condition to be added at Step Level.

XSD_type : data type of additional condition and mandatory indicator.

data : ls_condition like line of ct_condition.
data : ls_parameter like line of ct_parameter.
ls_condition-id = 1.
ls_condition-subject = 'BAdI: Procurement for Supplier Material XYZ'.
ls_condition-type    = if_swf_flex_ifs_condition_def=>cs_condtype-start_step.
append ls_condition to ct_condition.

ls_parameter-id = 1.
ls_parameter-name = 'XYZ'.
ls_parameter-xsd_type = if_swf_flex_ifs_condition_def=>cs_xstype-string.
ls_parameter-mandatory = abap_false.
append ls_parameter to ct_parameter.

After written the code, click on save draft and publish the logic.

 

#Step 2: –

To evaluate defined pre-condition / step condition against the newly created BO. I have implemented custom BADI SWF_WORKFLOW_CONDITION_EVAL.

Repeat same steps as above to create the BADI implementation, but this time in BADI description select “Value evaluation of addition conditions for scenarios”.

BADI – SWF_WORKFLOW_CONDITION_EVAL, Method: EVALUATE_CONDITION

Parameters:

IS_SAP_OBJECT_NODE_TYPE

Fields: –

SONT_KEY_PART_1-> Purchase requisition number

SONT_KEY_PART_2 -> Purchase requisition item number

 

IS_CONDITION

Fields: –

condition_id -> Unique ID of the additional condition

 

IT_PARAMETER_VALUE

Fields: –

Name -> Name of parameter in workflow in Manage workflow app

Value -> Value of parameter mentioned in workflow in Manage workflow app

 

CV_IS_TRUE

Should be set as true if the additional condition evaluation is successful

 

Check the sample code that can be used.

  1. CV_IS_TRUE is parameter to activate the workflow,

cv_is_true = abap_false.

 

  1. Reading parameter table with Pre condition that i have set in first BADI implementation.
READ TABLE it_parameter_value INTO DATA(ls_param_value)
WITH KEY name = 'XYZ'.

     2. Get the data of Purchase requisition from API where sont_key_part_1 is the PR number and sont_key_part_2 is the PR item number.

SELECT * INTO TABLE @lt_purchaserequisition
FROM i_purchaserequisition_api01
WHERE purchaserequisition = @is_sap_object_node_type-sont_key_part_1
AND purchaserequisitionitem = @is_sap_object_node_type-sont_key_part_2.

 

4. Checking the condition step and maintained value for XYZ in supplier material number”, if Pre-condition is XYZ and supplier material is also XYZ then workflow is activated for this custom pre condition.

CASE ls_param_value-value.
WHEN 'XYZ'.
READ TABLE lt_purchaserequisition INTO DATA(ls_purreq)
WITH KEY SupplierMaterialNumber = ls_param_value-value.
IF sy-subrc = 0.
cv_is_true = abap_true.
ELSE.
cv_is_true = abap_false.
ENDIF.
WHEN OTHERS.
cv_is_true = abap_false.
ENDCASE.

Click on save draft and publish the logic.

 

#Step 3: –

Testing: –

Create the Workflow

Go to App “Manage workflow app for purchase requisition” .

Select the scenario “Release for purchase requisition item” because we have given filter condition during BADI implementation.

Now the list has been extended with new custom pre-condition. Select Procurement for supplier material XYZ.

Select recipient in the step sequence to whom you send the mail for approval.

Click on SAVE and Active to activate the workflow.

Note:- Please keep the order of this new workflow at 1st position, because system is checking  the  order in which workflow is defined and then if there is any pre-conditions defined to start the workflow. At a time only one workflow will get trigger who satisfy the condition and was top in order.

Create Purchase Requisition: –

Go to App “Manage Purchase Requisition“.

Now Create Purchase Requisition with value in Supplier material number as ‘XYZ’ and SAVE, custom workflow will get trigger for approval.

Check your inbox, go to workflow and check the status.

I have tested by approving the workflow and then go to step condition where I can see my start pre-condition BAdI: Procurement for XYZ are met that I have defined in workflow.

 

 

___________________________

Learn > Share > Grow

Lot more to come. Stay tuned for my next blog post about data accessing techniques in SAP S/4HANA Cloud Fragmented Forms.

Assigned Tags

      18 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Gaurav Karkara
      Gaurav Karkara

      Good job Gaurav.

      Author's profile photo Gaurav Jain
      Gaurav Jain
      Blog Post Author

      Thanks.

      Author's profile photo Kamal Jain
      Kamal Jain

      Well explained Gaurav. This is very useful information for most of the cloud customers.

      Thanks for sharing.

      Author's profile photo Gaurav Jain
      Gaurav Jain
      Blog Post Author

      Thanks Kamal.

      Author's profile photo Ravish Ranka
      Ravish Ranka

      Good One. Thanks for sharing.

      Author's profile photo Gaurav Jain
      Gaurav Jain
      Blog Post Author

      Thanks Ravish.

      Author's profile photo Supply (South32) Arnold Wiggins
      Supply (South32) Arnold Wiggins

      Thanks for sharin

      Author's profile photo Mithun Kumar
      Mithun Kumar

      A quick question.

      Is the old flex workflow WS00800173 no longer used now?

      Also I heard that the workflow WS00800173 was hardcoded somewhere to be triggered for PR Item release. Is that resolved now, to point to the new WS02000471 via configuration?

      Author's profile photo Siow Fong Chen
      Siow Fong Chen

      Thanks for the information. Do you know whether this feature is available in the 1909 on premise solution?

      Cheers

      SF

      Author's profile photo PRADEEP MATHIVANAN
      PRADEEP MATHIVANAN

      Thanks for the detailed document. Is this applicable only for Procurement process or even for Journal Entry parking? The custom logic shows only for Procurement in 1909 - Onpremise. Please advice.

      Author's profile photo GITTON Laurent
      GITTON Laurent

      Great job. How are the parameter values mapped with the workflow. Where did the parameter value come from ?

      Laurent

      Author's profile photo Gaurav Jain
      Gaurav Jain
      Blog Post Author

      At condition step in Manage Workflow App, where you defined the Pre-condition, we need to mention the value for that pre-condition, that value will get it from parameter value.

       

      Author's profile photo Balakoti Reddy
      Balakoti Reddy

      Hi Gaurav,

      Any idea, how we can maintain the parameter values dynamically ( the parameter values should come from back end tables)

       

      Thanks

      Balu

      Author's profile photo Gaurav Kashinath Pednekar
      Gaurav Kashinath Pednekar

      Hi Gaurav,

      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?

       

      Author's profile photo Utkarsh Rastogi
      Utkarsh Rastogi

      Hi Gaurav,

      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.

      Author's profile photo Rakesh Reddy
      Rakesh Reddy

      Hi Utkarsh,

      I guess you got this solution. I am facing same issue. I understand that BADI triggers twice. But when it triggers BADI  for first time it is trying to determine workflow and giving out the error in PO (hence not allowing me to save PO). Plz let me know if you i need to avoid this Evaluation BADI for first time.

       

      Thanks,

      Rakesh Male.

      Author's profile photo Bijesh RB
      Bijesh RB

      Hi gaurav,

      How to give alterantive cds entity for purchase requisition and purchase requisition item.

      SELECT * INTO TABLE @lt_purchaserequisition
      FROM i_purchaserequisition_api01
      WHERE purchaserequisition = @is_sap_object_node_type-sont_key_part_1
      AND purchaserequisitionitem = @is_sap_object_node_type-sont_key_part_2.

       

      i_purchaserequisition-api01 is ---------->deprecated

      I_PurchaseRequisitionAPI01, I_PurchaseRequisitionItemAPI01 ---> this is the alternative cds entity for header and item.

      how to give?

      I am checking condition with requisitioner for item level pr.

       

       

      Thanks,

      Bijesh RB.

       

      Author's profile photo Jean-David Legrand
      Jean-David Legrand

      Hi Gurav,

      Thanks for the detailed explanation.

      If the custom pre-condition is not met, the status of the PR is "Awaiting approval". I was expected that the PR will be approved automatically.

      Any idea how to approach this issue?

      Thanks

      Regards,

      David