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-configu...
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:
- WS00800157 - Release of Purchase Requisition Header Level
- WS00800173 - Release of Purchase Requisition Item Level
- WS02000434 - Release of Central PR Header Level
- WS02000438 - Release of Central PR Item Level
- WS02000458- Release of Purchase Requisition for header level using the APP Manage Workflow for Purchase Requisitions – New
- WS02000471- Release of Purchase Requisition for item level using the APP Manage Workflow for Purchase Requisitions – New
- WS00800251- Workflow for blocked invoices
- WS00800303 - Workflow for parked invoices as complete
- WS00800238 - Workflow for Purchase Orders.
#Step 1 :-
BAdI's Implementation
- New pre conditions can be defined using custom BADI SWF_WORKFLOW_CONDITION_DEF.
- 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.
- CV_IS_TRUE is parameter to activate the workflow,
cv_is_true = abap_false.
- 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.