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

S/4HANA Flexible Workflows: Workflow Scenario Development and Configuration

Alan has suggested in his blogs that SAP Business Workflow Builder (SWDD) is not the recommendation anymore in S/4HANA. Workflow processes which are not spread across different systems, should make use of workflow scenario development. Alan’s blogs should give you fair idea about the reasons behind this recommendation. It is important to go through this blog and associated blogs before reading further.

There are many standard workflow scenarios available in transaction SWDD_SCENARIO / SWDD_SCENARIO_DISP, which I referred to understand S/4HANA flexible workflows. For a hands-on experience and to feel confident about a topic, it is important to develop something yourself from scratch. So, I decided to develop a simple and full custom workflow scenario and to configure it in Manage Workflows application. In this blog series, I will share the steps I followed and how simple eventually it is for business / key users to configure/change a workflow.

This workflow process is to update table entries in a custom table. Entry is created through a program and then entry goes through 2-step approvals before finally being created in custom table. Important information regarding the development:

  1. Custom table is for a hypothetical user master with a few fields.
  2. Business user should be able to decide the company id for which entry is created in table, at workflow level and step level. This will be achieved by creating a condition in workflow scenario.
  3. For simplicity reasons, approver for both the steps would be workflow initiator. However, it is possible to define own approvers or define different rules to determine the approver.
  4. First approval step is to validate the entered user data and second approval step to finally give the approval to create records in custom table.
  5. We will make use of framework provided exceptions. Though, it is possible to define custom exceptions. So, no specific exception related processing is done.
  6. There could be various better ways to achieve the same requirement. This blog strives to show the simplicity and steps for a flexible workflow – workflow scenario.
  7. This blog just shows a very limited set of flexible workflow’s capabilities. I have seen that most of the SWDD workflow builder’s capabilities are possible in flexible workflow, with better control, handling and in much cleaner way.

System: S/4HANA 1809

Custom Table

A custom table is created with fields related to a user. There is no foreign key validation for person ID or other fields. Below table would be updated at the successful completion of workflow process:

Entry Program

A program is created to enter field values through a selection-screen. This program then raises the workflow event and passes the field values as event parameters. Event is already defined in workflow class and parameters are associated with the same event. We will see more details regarding this class in further sections:

TABLES: zcustusermast.

DATA:ls_key        TYPE pernr,

     lv_objtype    TYPE sibftypeid,
     lv_event      TYPE sibfevent,
     lv_objkey     TYPE sibfinstid,
     ls_event_data TYPE zcustusermast.

PARAMETERS: p_person TYPE zcustusermast-person_no,
            p_first  TYPE zcustusermast-first_name,
            p_last   TYPE zcustusermast-last_name,
            p_comp   TYPE zcustusermast-company_id,
            p_cmploc TYPE zcustusermast-company_loc,
            p_bldz   TYPE zcustusermast-building_zone.

lv_event = 'CREATED'.

*SET up the lpor instance id
lv_objkey = p_person.

*Instantiate an empty event container

DATA(lr_event_parameters) = cl_swf_evt_event=>get_event_container(
                              im_objcateg = cl_swf_evt_event=>mc_objcateg_cl
                              im_objtype  = lv_objtype
                              im_event    = lv_event ).

ls_event_data-person_no = p_person.
ls_event_data-first_name = p_first.
ls_event_data-last_name = p_last.
ls_event_data-company_id = p_comp.
ls_event_data-company_loc = p_cmploc.
ls_event_data-building_zone = p_bldz.

        name       =  'IS_DATA'                " Name of Parameter Whose Value Is to Be Set
        value      =  ls_event_data               " Value
  CATCH cx_swf_cnt_cont_access_denied. " Changed Access Not Allowed
  CATCH cx_swf_cnt_elem_access_denied. " Value/Unit Must Not Be Changed
  CATCH cx_swf_cnt_elem_not_found.     " Element Not in the Container
  CATCH cx_swf_cnt_elem_type_conflict. " Type Conflict Between Value and Current Parameter
  CATCH cx_swf_cnt_unit_type_conflict. " Type Conflict Between Unit and Current Parameter
  CATCH cx_swf_cnt_elem_def_invalid.   " Element Definition Is Invalid (Internal Error)
  CATCH cx_swf_cnt_container.          " Exception in the Container Service

*RAISE the event
    CALL METHOD cl_swf_evt_event=>raise
        im_objcateg        = cl_swf_evt_event=>mc_objcateg_cl
        im_objtype         = lv_objtype
        im_event           = lv_event
        im_objkey          = lv_objkey
        im_event_container = lr_event_parameters.
  CATCH cx_swf_evt_invalid_objtype .
  CATCH cx_swf_evt_invalid_event .

Workflow Scenario

This is where our real workflow development starts. Create a new workflow scenario in transaction SWDD_SCENARIO. Enter Abbreviation, description details as they are free-text.

Since we are creating class- based workflow scenario, we will have to create a SE24 global class with ‘IF_WORKFLOW’ as implemented interface and implement required interface methods. We created the below class:

Also, created is the event that is being raised from entry program with associated parameters:

Process Data

Create a workflow container element with reference to workflow class. This element will be our leading object for the scenario. It is mandatory to define one leading object and this element will be accessible throughout the workflow.


By default, system proposes definition base class and runtime base class as callback classes. For our scenario, we have created class ‘ZCL_CUSTUSER_RUNTIME_DATA’ as subclass of base class ‘CL_SWF_FLEX_IFS_RUN_APPL_BASE’. We will need to implement/redefine some methods in this class, which we will cover in subsequent sections.


We have 2 ‘User Decision’ activities, means these two activities will be available for us while configuring the workflow. We will be able to define approvers for these activities. There is possibility to define a ‘Activity’ step as well, which won’t require any processor and will be available during configuration. If activity is checked as ‘Activity for Results Processing’, it means this activity will react to an outcome and won’t be available as a step during configuration.

These activities, depending on type, will be shown as ‘Step Types’ while configuring Workflow in ‘Manage Workflow’ application.

Activity 1: Validate Data

Approver will be provided with the table record information as work item text. Defined decision texts will be provided and based on POSITIVE / NEGATIVE outcome, further steps can be triggered.

Title                – This text will be shown as subject of work item.

Decision Texts – These texts will be shown as decision options in work item.

Define the character of outcome under tab ‘Outcomes’:

‘NEGATIVE’ outcome will be shown in ‘Manage Workflow’ application while configuring the exception handling for this step.

TS00008267 is proposed as standard decision task. This task should be copied to a custom task and work item description can be defined as required.

Activity 2: Create Record

This approval step is for a final approval to create the records in table. As defined in activity 1, define the work item subject and other details. Copy the Standard decision task and change as required:

‘NEGATIVE’ outcome will be shown in ‘Manage Workflow’ application while configuring the exception handling for this step.


Under ‘Conditions’ tab, we define the workflow start condition or step start conditions. We are providing the condition to enter field value for ‘Company ID’ as workflow start condition or step start condition.

These conditions will be shown as ‘PRECONDITIONS’ in ‘Manage Workflow’ application.

Save, Activate and fix any errors if encountered. Workflow scenario development is almost complete. We will see the run time callback class in part 2. We will also look at Workflow configuration and test our workflow.

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Parth Vaishnav
      Parth Vaishnav

      Hello Gaurav,

      a very good article throwing lot of insights..

      just have a little query..

      the general we get requirements to add email steps in standard workflow and mail template functionality is not available before in 1909 on premise and 1905 cloud versions. Since delegation of BO is easy but not for class, i was  thinking to copy standard WF scenario into Z-scenario and change the class to this Z-class which is copy of existing std. class and will add required mail sending logic in methods of this Z-class.

      This is where i found that class name is fixed(hard-coded) in calling(triggering) application. so I had a workaround of calling a piece of code to trigger same event but of my Z-class. this i achieved by writing this code in appropriate BAdi(or userexit) called "save" time of object(my object is Purchase Order) .

      So is this  workaround the only way? or  is there any other better way to do it.

      Author's profile photo Modak Gupta
      Modak Gupta

      Yes - there are Fiori Enhancements which provide you all the work item instance data when you Approve/Reject a workitem or even when a workitem is created . So you can generate emails when approves get a workitem (though I prefer Extended Notifications - which is still there in S/4), notifications after the Approval / Rejection. In this way , you do not have to touch standard workflows. Check enhancement spot /IWWRK/ES_WF_WI_BEFORE_UPD_IB

      Author's profile photo Modak Gupta
      Modak Gupta

      Gaurav , this is a great step by step guide to build "modern" workflows 🙂  . I like the details with which you have provided understanding of back-end (workflow scenario definition) and how (in your second blog) these are used by the business user.



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

      Thanks Modak.

      Author's profile photo Nabheet Madan
      Nabheet Madan

      First of all thanks Gaurav for writing about the flexible workflows. I had a very high level understanding of them. But after readying your blog posts and the pre-requistes helps me in understanding them better. The impact of your blog is i have SWDD_SCENARIO open on my system now:)

      Thanks once again keep rocking!

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

      Thanks Nabheet!

      Author's profile photo Sumit Kumar Kundu
      Sumit Kumar Kundu

      Thanks Gaurav for the wonderful blog! Hope you are doing well!

      BTW, the link to another blog post you referred at the beginning is not working. Is the blog still there?



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

      Thanks Sumit.

      Yes, it looks like blog is deleted. I have removed the reference from my blog. Enjoy!!

      Author's profile photo Kanwardeep Singh Gill
      Kanwardeep Singh Gill

      Very informative blog, Gaurav!


      One thing I would like to understand is that how does the underlying content CDS gets associated with the Leading Object? If you could elaborate on that it would be really helpful.

      Author's profile photo Yu Ota
      Yu Ota

      Thank you for explaining Flexible Workflow. It was a very easy-to-understand explanation. I have a question about Flexible Workflow. Is it possible to implement a business workflow or scenario with SAP GUI and link it with the Fiori tile for a workflow that does not have a scenario (for example, a workflow for debts and credits)? Also, in that case, do you recognize that the implementation of Business Workflow requires Class or Badi for posting and approval? Please confirm.

      Author's profile photo Yu Ota
      Yu Ota

      I would like to know if there are any useful blogs or books.

      Author's profile photo Kishor Sarode
      Kishor Sarode

      Hi Gaurav,

      followed all your steps and created scenario in manage workflow app;

      1>My first error is not able to activate workflow scenario in fiori app, as there is no activate button available.

      2> Not able to trigger the FWF, I guess its due to non activation;

      so when I run FWF I got error "task definition not found;

      requesting your suggestion on this;



      K S


      Author's profile photo Suresh Subramanian
      Suresh Subramanian

      Excellent !

      Author's profile photo Danilo Faleiros Depolli
      Danilo Faleiros Depolli

      Hello Gaurav,

      Excellent post.

      I have a doubt regarding the LEADING_OBJECT, could you help me?

      When activate the Workflow the PFTC generate a new Definition Language (ZSWFC_90000008 for example), in my CDS the __LEADING_OBJECT association is missing and it's generating an error in the approvers defined in the Teams and Responsibilities, do you know what is required to do for insert the LEADING_OBJECT in this CDS? We have the Company Code filter, but when creates two Teams for differente company code, it's is not working and the approval task are sent to both approvers

      Any suggest is appreciated and thank you in advance.


      Author's profile photo Yan Qun
      Yan Qun

      Hi Gaurav,

      Thanks for sharing. We have a question about custom flexible workflow, we want to assign user as receive directly as standard Purchase order flexible workflow, not by custom rule. How do we configure this ? Thanks!

      Author's profile photo jeevitha k
      jeevitha k

      Hi Gaurav,

      I have one requirement Creating return order from Service notification.

      We don't have standard BO\ABAP Class. So need to start from scratch.

      1. I have created class for event ZCL_CUSTOM_WF~CREATED by referring standard interfaces BI_OBJECT
      2. Parameters are IV_INITIATOR,IV_OBJECT_ID(Key) and workflow container is of type ZCL_CUSTOM_WF which has key attributes VBELN,AUART and non key table MT_SALES_ORDERS.
      3. I tried to fill workflow container using constructor method as like CL_MM_PUR_WF_OBJECT_PO~Constructor
      4. Work item is created from SWUE tcode and reaching inbox but workflow container elements are not getting filled.
      5. Run time class also implemented ZCL_SWF_FLEX_IFS_RUN_APPL_BASE~AFTER_COMPLETION_CALLBACK and result_call_back methods. But these are getting triggered when we click on approve from myinbox.

      Kindly help me on this.


      Thanks & Regards,

      Koduru Jeevitha



      Author's profile photo Arun Kumar Agrawal
      Arun Kumar Agrawal

      Hi Koduru,

      Try to fill WF container from Runtime base class Method  IF_SWF_FLEX_IFS_RUN_APPL_STEP~BEFORE_CREATION_CALLBACK.

      • Read Container

      DATA(lo_container) = io_context->get_workflow_container( ).

      lo_container->get( EXPORTING name = 'ELEMENTNAME' IMPORTING value = Data value from container ).

      • Use below to get the instance id like Object Key

      ls_obj_key = lv_data_value-instid.
      CATCH cx_swf_flex_ifs_run_exception .

      *Prepare LS_DATA

      * Set data in container
      CALL METHOD io_context->get_workflow_container( )->set(
      name = 'ELEMENTNAME
      value = ls_data ).

      CATCH cx_swf_cnt_cont_access_denied .
      CATCH cx_swf_cnt_elem_access_denied .
      CATCH cx_swf_cnt_elem_not_found .
      CATCH cx_swf_cnt_elem_type_conflict .
      CATCH cx_swf_cnt_unit_type_conflict .
      CATCH cx_swf_cnt_elem_def_invalid .
      CATCH cx_swf_cnt_container .



      Arun Agrawal

      Author's profile photo jeevitha k
      jeevitha k

      Hi Arun,

      Thank you and it helped me a lot.

      Thanks & Regards,

      Koduru Jeevitha

      Author's profile photo jeevitha k
      jeevitha k

      Hi Arun,

      Thank you and it helped me a lot.

      1. If we have to add users from F4 i didn't get option in Manage Workflow fiori app. How to add users for the approval task?
      2. like standard if approvers rejects it should go to initiator.
      3. If we have multi levels of approvals how to configure approvers? Can we do it Teams & Responsibilities.

      Kindly help me on this.


      Thanks & Regards,

      Koduru Jeevitha