In this blog post I will share my requirements and solution on adding Custom Pre-Conditions in Flexible Workflow for Overall Release of PR approval.  I have also shown below how to add value help for the precondition defined.

 

Requirement 

  • Add following preconditions to the “Manage Workflows for Purchase Requisitions” F2705 App in S4HANA 2021:
  1. Account Assignment Category
  2. Plant
  3. Requisitioner
  • Add F4 value help to the above defined preconditions.

 

Environment

S4HANA on Premise 2021, SAP S/4HANA 2021, S4CORE 106

Solution

SAP has given some standard predefined conditions while configuring a flexible Workflow for Purchase Requisition Approval, but we can also add our own pre-conditions.

To add custom new preconditions in Flexible Workflow SAP has given a BADI SWF_WORKFLOW_CONDITION_DEF to enhance and add your required fields in the preconditions tab.

Along with this we also need to add evaluation logic for these custom defined pre-conditions in BADI SWF_WORKFLOW_CONDITION_EVAL.

So basically BAdI SWF_WORKFLOW_CONDITION_DEF allows you to create the fields for key and value to add in the start and step conditions and SWF_WORKFLOW_CONDITION_EVAL helps in valuating the value part of these fields.

 

Now let’s begin.!

#STEP 1:

SWF_WORKFLOW_CONDITION_DEF Implementation

First we need to activate and assign Custom Logic App to our id in S4HANA (which I have already done, will try to add a blog for this information too 🙂 ).

Open Custom Logic App > Tab Custom Logic >  “+” icon at the top right corner next to search bar:

Custom Logic App

Now you will see a pop-up window to add new enhancement implementation, enter following details to create the new implementation for Pre-Conditions:

Business Context: Procurement: Start and Pre-Conditions in Flexible Workflow (select from dropdown help)

BAdI Description: Providing additional conditions for scenarios (select from dropdown help)

Implementation Description: Add Preconditions for PR Scenario (this is custom text can be changed as per your requirement)

Implementation ID: PRECONDITIONS (custom text can be changed as per your requirement)

Pre-Condition Implementation Details

Once added a new implementation will get created and you will be navigated to the screen as below:

Pre-Condition Implementation Draft

The implementation gets created with a sample logic for reference.

Click on Filter tab and “+” icon to add you scenario id so that these preconditions will only be added to that scenario.

Scenario%20Id%20added%20to%20Filter%20Tab

Scenario Id added to Filter Tab

 

In our case I have added scenario_id = WS02000458 ( this scenario is for Overall PR Release)

Click on SAVE.

 

To check other scenarios, you can refer to this SAP help link:

https://help.sap.com/docs/SAP_S4HANA_ON-PREMISE/af9ef57f504840d2b81be8667206d485/a84badfeaf0445f4bed2a5c9bb0ed9c2.html

 

Next, we have following parameters in the code:

  • CT_CONDITION

Fields –

ID: Unique ID of the additional condition

subject: Name of the additional condition

type: Condition to be added at step level (type =

if_swf_flex_ifs_condition_def=>cs_condtype-step)

or

at both of step level and workflow level (type = if_swf_flex_ifs_condition_def=>cs_condtype-start_step)

 

  • CT_PARAMETER

Fields-

ID: Unique ID of the additional condition

Name: Name of the additional condition

xsd_type: Data type of the additional condition (supported data types are Boolean, date, string, integer, and time)

mandatory: To indicate the additional condition is mandatory.

service_path – the service path of your OData Service

entity – the Value Help entity of your OData Service

property – the field/property in your OData Service for your field value.

 

In my case for Account Assignment Category and Plant I have used SAP standard CDS  “S_MMPURWorkflowVH” and its equivalent OData service “S_MMPURWorkflowVH_CDS”.

Entity exposing these fields is “S_MMPURWorkflowVH”

For Requisitioner value help we are using a custom table ZPR_DEPT, hence I created a CDS view value help exposing the values of this table which you can check at the end of this blog.

Add the code as below:

  1. Create two data variables to append to ct_condition and ct_parameter.
    data : ls_condition like line of ct_condition.
    data : ls_parameter like line of ct_parameter.
  2. Define condition for Account Assignment Category, OData service used for value help is standard “S_MMPURWORKFLOWVH_CDS” and entity used is ‘S_MMPURWorkflowVH’
    * Acc Assignment Category condition
    ls_condition-id = 'idAcc'.
    ls_condition-subject = 'Account Assignment Category is'.
    ls_condition-type    = if_swf_flex_ifs_condition_def=>cs_condtype-start_step.
    append ls_condition to ct_condition.
    
    ls_parameter-id = 'idAcc'.
    ls_parameter-name = 'AccAssgnmtCate'.
    ls_parameter-xsd_type = if_swf_flex_ifs_condition_def=>cs_xstype-string.
    ls_parameter-service_path = '/sap/opu/odata/sap/S_MMPURWORKFLOWVH_CDS'.
    ls_parameter-entity       = 'S_MMPURWorkflowVH'.
    ls_parameter-property     = 'AccAssgnmtCat'.
    ls_parameter-mandatory = abap_false.
    append ls_parameter to ct_parameter.
    
  3. Define condition for Plant, OData service used for value help is standard “S_MMPURWORKFLOWVH_CDS” and entity used is ‘S_MMPURWorkflowVH’
    * Plant condition
    ls_condition-id = 'id_Plant'.
    ls_condition-subject = 'Plant is'.
    ls_condition-type    = if_swf_flex_ifs_condition_def=>cs_condtype-start_step.
    append ls_condition to ct_condition.
    
    *Parameter for Workflow level condition - Plant
    ls_parameter-id = 'id_Plant'.
    ls_parameter-name = 'Plant'.
    ls_parameter-xsd_type = if_swf_flex_ifs_condition_def=>cs_xstype-string.
    ls_parameter-service_path = '/sap/opu/odata/sap/S_MMPURWORKFLOWVH_CDS'.
    ls_parameter-entity       = 'S_MMPURWorkflowVH'.
    ls_parameter-property     = 'Plant'.
    ls_parameter-mandatory = abap_false.
    append ls_parameter to ct_parameter.
  4. Define condition for Requisitioner, OData service used to value help is custom “ZC_PR_DEPT_VH_CDS” and entity used is ”ZC_PR_DEPT_VH’ (At the end of this blog I have shown how to create CDS view and OData service for this.)
    * Requistioner Condition
    ls_condition-id = 'id_Req'.
    ls_condition-subject = 'Requisitioner is'.
    ls_condition-type    = if_swf_flex_ifs_condition_def=>cs_condtype-start_step.
    append ls_condition to ct_condition.
    
    ls_parameter-id = 'id_Req'.
    ls_parameter-name = 'Requisitioner'.
    ls_parameter-xsd_type = if_swf_flex_ifs_condition_def=>cs_xstype-string.
    ls_parameter-service_path = '/sap/opu/odata/sap/ZC_PR_DEPT_VH_CDS/'.
    ls_parameter-entity       = 'ZC_PR_DEPT_VH'.
    ls_parameter-property     = 'ReqDept'.
    ls_parameter-mandatory = abap_false.
    append ls_parameter to ct_parameter.
    

Final Code will look like this:

Now, click on “Save Draft” at the bottom of your screen and then click on “Test” to check your code.

After this once you click on “Publish” your changes will get activated and published in the system.

PLEASE NOTE: fields you add in the pre-conditions please add in Alphabetical order i.e., Account Assignment first then Plant and then Requisitioner, if not added in this order while testing the logic you will get error.(this is something I figured out on my own and I did not find in any of the blogs, so sharing here hoping it will save someone’s time and no one will bang their head on wall thinking where they went wrong.)

#STEP 2:

SWF_WORKFLOW_CONDITION_EVAL Implementation

Ok, so now moving on to adding evaluation implementation.

Same steps: Custom Logic > + > Add Implementation Details > Create.

Please note this time select BAdI “Value evaluation of additional conditions for scenarios.”

Business Context: Procurement: Start and Pre-Conditions in Flexible Workflow (select from dropdown help)

BAdI Description: Value evaluation of additional conditions for scenarios (select from dropdown help)

Implementation Description: Evaluation of additional conditions for PR scenario (this is custom text as per your needs)

Implementation ID: VALUATEPRECONDITIONS (custom text as per your needs)

Evaluation%20Implementation%20Details

Evaluation Implementation Details

Add the filter for Scenario id :

You will see some sample code for reference.

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)
  • I_PurchaseRequisitionItemAPI01 – CDS entity for PR header and item

Logic added as below:

  1. Reading PR details from API I_PurchaseRequisitionItemAPI01 into a local table
IF is_sap_object_node_type-sont_key_part_2 IS INITIAL.
  SELECT  * INTO TABLE @DATA(lt_purchaserequisition)
    FROM i_purchaserequisitionitemapi01
    WHERE purchaserequisition = @is_sap_object_node_type-sont_key_part_1.
ELSE.
  SELECT  * INTO TABLE @lt_purchaserequisition
    FROM i_purchaserequisitionitemapi01
    WHERE purchaserequisition = @is_sap_object_node_type-sont_key_part_1
    AND purchaserequisitionitem = @is_sap_object_node_type-sont_key_part_2.
ENDIF.
  1. Reading parameter table with Pre-condition value for Account Assignment Category and compare it with the value from PR data. Please note that the key name needs to match with the parameter name defined in the pre-condition BAdI. In this case, it is ‘AccAssgnmtCate’
READ TABLE lt_purchaserequisition INTO DATA(ls_purreq) INDEX 1.
READ TABLE it_parameter_value INTO DATA(ls_param_acc) WITH KEY name = 'AccAssgnmtCate'.
IF sy-subrc EQ 0.
  CONDENSE ls_param_acc-value NO-GAPS.
  CONDENSE ls_purreq-accountassignmentcategory NO-GAPS.
  IF ls_param_acc-value = ls_purreq-accountassignmentcategory.
    cv_is_true = abap_true.
  ELSE.
    cv_is_true = abap_false.
  ENDIF.
ENDIF.

Similarly for Plant and Requisitioner:

READ TABLE it_parameter_value INTO DATA(ls_param_plant) WITH KEY name = 'Plant'.
IF sy-subrc EQ 0.
  IF ls_param_plant-value = ls_purreq-plant.
    cv_is_true = abap_true.
  ELSE.
    cv_is_true = abap_false.
  ENDIF.
ENDIF.
READ TABLE it_parameter_value INTO DATA(ls_param_req) WITH KEY name = 'Requisitioner'.
IF sy-subrc EQ 0.
  IF ls_param_req-value = ls_purreq-requisitionername .
    cv_is_true = abap_true.
  ELSE.
    cv_is_true = abap_false.
  ENDIF.
ENDIF.

 

Entire code would look something like this:

#STEP 3:

Configure Workflow:

Now when we open the “Manage Workflows for Purchase Requisitions” F2705 App, we will be able to see our preconditions along with Value help window to select from.

Click F4 for value help window:

#STEP 4:

Custom CDS View and OData Service for Value Help:

Now, let us see how to create CDS view for Value help.

As already mentioned above in my case we have a custom table to where we are maintaining Requisitioner data.

  1. I created a base CDS view first to expose the Req_Dept field from this table:
@AbapCatalog.sqlViewName: 'ZBPRDEPT'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Base View exposing ZPR_DEPT'
@VDM.viewType: #COMPOSITE
@ObjectModel.representativeKey: 'ReqDept'
@Search.searchable: true
define view ZB_PR_DEPT as select from zpr_dept {
@Search.defaultSearchElement: true
    key req_dept as ReqDept
}
  1. Create a consumption CDS view which will be exposed as OData service for value help:

Use OData.publish annotation to publish OData service and Consumption.valueHelpDefinition to create value help on the base CDS view created above.

@AbapCatalog.sqlViewName: 'ZCPRDEPTVH'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Value help for Requisitioner Dept'
@ObjectModel.dataCategory:#VALUE_HELP
@OData.publish: true
@ObjectModel.createEnabled: true
define view ZC_PR_DEPT_VH  as select from zpr_dept {
 @Consumption.valueHelpDefinition: [{entity: { name: 'ZB_PR_DEPT', 
                                                      element: 'ReqDept'  }}]
key req_dept as ReqDept
}
  1. Activate the CDS views and go to Tcode : /n/IWFND/MAINT_SERVICE to add and generate metadata of the newly created OData service in the system.

Test in gateway client the service should execute with entity ZC_PR_DEPT_VH:

 

That’s all from my side friends. Hope this blog helps someone who is new and looking out for more information on Flexible Workflows. I will try to add more parts to this series mentioning my entire end to end Overall PR Release requirement and solution including details on Configuring multi-level approval in Flexible WF with alternative preconditions, activating and maintaining email templates and configure My Inbox and test end to end PR creation with approval.

Thank you for your read.

Ciao.!

Tasneem Khilonawala

References:

https://launchpad.support.sap.com/#/notes/2767845

https://blogs.sap.com/2019/12/03/sap-s-4hana-cloud-flexible-workflow-with-new-custom-pre-condition-for-purchase-requisition/

https://blogs.sap.com/2020/07/06/f4-help-in-custom-pre-conditions-for-flexible-workflow-manage-workflow-for-purchase-requisition/

 

Sara Sampaio

Sara Sampaio

Author Since: March 10, 2022

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x