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

S/4HANA Cloud(S4HC) provides the new Flexible Workflow, that you can manage using “Manage Workflow App”. In this blog I am covering how to implement Custom Pre-conditions in S4HC Workflow. Please check the below link to understand the standard Pre-conditions in S4HC Workflow for Purchase Order as example: S/4HANA Cloud - Flexible Workflow for Purchase Order Approval


In environment of S4HC, it provides a new functionality where you can add new pre-conditions in Purchase requisition using Manage workflow app. In S4HC latest release, you will find 3 apps for Manage Workflow for Purchase Requisition, in that you need to select the NEW version of APP highlighted in below screen short.


There are basically two types of release for Purchase Requisition Workflow.





  1. Overall release of Purchase Requisition.

  2. Release of Purchase Requisition Item


  3. Based upon release type we have some standard pre condition defines. Preconditions are used to trigger the workflow if the conditions met during creation of purchase requisition.


    1.Overall release of Purchase requisition.


    Click on Add to create a new Workflow. To check the standard Pre condition click on Start Condition Tab and in dropdown list check the available Pre-Condition.



    2. 2. Release of Purchase Requisition Item


    Here you can see there are 2 custom pre condition that are visible after implementation of BADI



    Scenario:


    In this requirement we need to add the custom pre-condition for purchase requisition at Item level, so once you create purchase requisition and click on save, workflow will get trigger send for approval at item level. We need to trigger the workflow based upon value of standard field, if the value of standard field is “PRV” then custom workflow for PRV need to trigger and if value of standard field is PRS then workflow for PRS need to get trigger.There can be any standard and custom field(created for same business context). Here in this scenario we are using standard field “Service material number” to enter the value as PRV or PRS(as example), so if we create PR with Service Material Number entered value as PRV then Workflow for PRV need to get trigger and if we entered value as PRS the workflow for PRS get triggered.


    First, we need to create 2 custom workflow having custom condition step as PRV or PRS. For adding custom pre-condition, we are implementing BADI. You can use the “Custom Fields and Logic” app to create a BAdI implementation and publish the custom logic.


    Below are 2 custom pre condition that we are adding.




    1. Procurement for PRV




    2. Procurement for PRS



      These new custom conditions can be defined using BADI SWF_WORKFLOW_CONDITION_DEF.


      Once this BADI is implemented, then those pre-condition / step condition will be visible in the Manage Workflows app for the respective filter criteria.



      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



      For BADI implementation go to App “Custom Field and logic”.



      Go to tab Custom Logic.



      Click on “+” button top right corner of the system


      It will ask for New implementation details



      Select the business context as start and pre-condition in flexible workflow.


      Select BADI description as Proving additional condition for scenario.



      Click on create and your BADI implementation is created.


      Note: Always Check the following technical documentation and sample code for the BADIs before start implementation.



      BAdI - SWF_WORKFLOW_CONDITION_DEF, Method: GET_CONDITIONS


      Use: to define additional conditions for scenarios


      Parameters:


      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





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


      Go to filter tab and give scenario id as mentioned in list above



      Scenario WS02000471 is used for Release of Purchase Requisition for item level using the APP Manage Workflow for Purchase Requisitions – New.


      Save and Publish the logic.



      Open the APP Manage Workflow for Purchase Requisition-New, create a new workflow and check the custom pre conditions under “Start Condition”.





      Custom Precondition for PRV and PRS has been implemented using BADI, now we need to write the code to evaluate these custom pre condition.



      The defined pre-condition / step condition needs to be evaluated against the newly created BO. That will be done using the custom BADI SWF_WORKFLOW_CONDITION_EVAL.



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



      Repeat the 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 Use: to evaluate the additional conditions defined


      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.



      2. Reading parameter table with condition PRV AND PRS.


      READ TABLE it_parameter_value INTO DATA(ls_param_value)


      WITH KEY name = 'PRV'.


      READ TABLE it_parameter_value INTO ls_param_value


      WITH KEY name = 'PRS'.



      3. This workflow for PRV and PRS is designed for Item Level release of Workflow


      First, we need to fetch the data for PR using API based upon PR number and item, here is_sap_object_node_type-sont_key_part_1 contains the PR number and is_sap_object_node_type-sont_key_part_2 contains the 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 PRV and PRS in supplier material number", if condition is PRV and supplier material is PRV then workflow is active for PRV, if condition is PRS and supplier material number is PRS then workflow is active for PRS.



      CASE ls_param_value-value.


      WHEN 'PRV'.


      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.


      Checking the condition step and maintained value for PRV and PRS in suppiler material number"


      WHEN 'PRS'.


      READ TABLE lt_purchaserequisition into ls_purreq


      WITH KEY SupplierMaterialNumber = ls_param_value-value.


      IF sy-subrc = 0.


      "If Maintained Value is PRS then WF for PRS will get trigger else check the next condition"


      cv_is_true = abap_true.


      ELSE.


      cv_is_true = abap_false.


      ENDIF.


      WHEN OTHERS.


      cv_is_true = abap_false.


      ENDCASE.


      ENDIF.


      ENDIF.



      Finally, we need to create 2 workflows having custom pre conditions.



      1. Workflow with pre condition PRV.



      Go to “Manage Workflow App”









      Click on Add button




      Select the condition: BAdI: procurement for PRV and give value as PRV.


      In the Step Sequence select the recipient to send the workflow for approval. Enter the user for approval.




      Click on save and activate the Workflow.




      1. Workflow with pre condition PRS



      Same step needs to repeat for Pre-Condition PRS.




      Conclusion



      Now create PR and check your workflow triggers.


      Create the PR from “Purchase Requisition APP” and give the supplier number “PRV” or “PRS” based upon which workflow you need to trigger.





      Click on Save and workflow will get trigger.


      Check your inbox, go to workflow and check the status





      Workflow for Pre-Condition of PRV is triggered. If the service material field has value PRS is maintained, then workflow for Pre-Condition PRS will triggered.



      You can find the details for BADI in below mentioned note.


      Note: 2767845 ( https://launchpad.support.sap.com/#/notes/2767845 )






      8 Comments