SAP Flexible Workflow TCodes

1.   Background:

SAP Flexible Workflow TCodes: Flexible Workflow is a new concept introduced in SAP S/4HANA with the objective to simplify  workflow configuration. It is recommended that we use the new Flexible Workflow functionality in S/4HANA.

The flexible workflow is based on a set of predefined workflow scenarios and tasks. This provides the functionality to define condition-based workflow for different processes in the system.

It is possible to define single or multi step approval processes, and the relevant workflow items are made available in the My Inbox Fiori App for the approvers. Manage Workflows Fiori App is available to configure flexible workflow scenario, and these apps allow the Business process specialist to set up workflows based on the business requirement.

SAP pre-delivered many such flexible scenario in procurement, finance etc. and SAP help is available to set up/activate those templates. However, I found some difficulty to create custom template by using this new technology and integrate them in my inbox. To address that, I have prepared this blog post to fulfil one simple multi step scenario which we come across in every implementation

3.   Objects Involved in this development

  • Flexible workflow scenario Development
  • Responsibility rule to get L1 approver
  • Workflow Class to manage workflow
  • My inbox task configuration
  • Manage Workflow setup for custom workflow
  • Email Templates

4.   Flexible scenario development:

Tcode : SWDD_SCENARIO

New tcode being used to create flexible scenarios in S4 system. Flexible block is the main component which will play important role in scenario. We have to first decide all possible decision tasks and activities (background method executions) as per business requirement. As per our sample workflow, we have 3 decision tasks and 1 activity.

Create new flexible workflow scenario with class based.

Create one container element employee of class type to hold all employee object details :

Go to Header and update start event details. I have created one START event in custom class which will be used to trigger this WF.

Create all required activities as per business requirement. As per our sample requirements, we have user decision steps like Level1 Approval, Level 2 Approval, To Requestor and activity like Post Employee data by final approver.

Create all required Agent rules as per business conditions. For the sake of POC, I have used one responsibility rule with one agent maintained manually to get L1 Approver. But in real time scnario, these agents will be determined in FM based on some roles or any other conditions. That FM being used in PFAC rule.

PFAC Rule :

The moment we create activities in Flexible block, it will ask us to provide all task details for that activity. We need to provide required task details whether user decision or activity. I’m not going too much here as this is normal workflow functionality. The moment we create activity, then flow will be created for this activity. Since we have 4 activities in sample workflow, so we can see 4 flows visible in this workflow.

5.   Workflow Triggering logic (Workflow class logic )

Flexible workflow triggering is just same as classic workflow mechanism. We can trigger this either by using BO or Class events. I have created one simple method in class to trigger this wf with some event parameters. I’m passing employee details to workflow through start event for the sake of POC.

Redefine standard WF interface methods at least with empty implementation and activate class.

I have declared one public key attribute in this class and instantiated this value in constructor of the class.

START Event to trigger workflow

STARTWF method code to trigger this workflow: Below is the sample code to trigger workflow. In real time situations, you can use your own event parameters and populatate those. Based on your requirement, we will call this event in some exits, BADIs, Odata function imports or create/update methods or custom programs etc.

DATA lv_objkey        TYPE sibfinstid.
DATA ls_empdetails TYPE zhcm_st_telecommuting.
DATA lv_param_name       TYPE swfdname.
DATA lr_event_parameters TYPE REF TO if_swf_ifs_parameter_container.

DATA g_evt_param_container   TYPE REF TO if_swf_cnt_container.
DATA l_event_ref             TYPE REF TO if_swf_evt_event.
DATA vl_returncode           TYPE sysubrc.
DATA l_objtype               TYPE sibftypeid VALUE ‘ZCL_WF_EMPLOYEE_FLEX’.   DATA l_event                 TYPE swo_event VALUE ‘START’.
DATA l_event_container       TYPE REF TO if_swf_ifs_parameter_container.

lv_objkey = iv_employee.

CALL METHOD cl_swf_evt_event=>get_event_container
EXPORTING
im_objcateg  = cl_swf_evt_event=>mc_objcateg_cl
im_objtype   = l_objtype
im_event     = l_event
RECEIVING
re_reference = lr_event_parameters.
*
ls_empdetails-ei_employeeno = iv_employee.
ls_empdetails-ei_lastname = ‘Veshala’.
ls_empdetails-ei_firstname = ‘Naveen’.
ls_empdetails-ei_postitle = ‘Consultant’.
ls_empdetails-hr_telestartdate = sy-datum.
lv_param_name = ‘EMPDETAILS’.
*
CALL METHOD lr_event_parameters->set
EXPORTING
name  = lv_param_name “#EC NOTEXT
value = ls_empdetails.
**
TRY.
CALL METHOD cl_swf_evt_event=>raise
EXPORTING
im_objcateg        = cl_swf_evt_event=>mc_objcateg_cl
im_objtype         = l_objtype
im_event           = l_event
im_objkey          = lv_objkey
im_event_container = lr_event_parameters.

CATCH cx_swf_evt_invalid_objtype.
CATCH cx_swf_evt_invalid_event.
ENDTRY.

COMMIT WORK.

6.   Manage Workflow App – Workflow development and activation

Open Manage Workflow app in Fiori launch pad and configure new workflow based on our custom template. As per our flow, we have 3 steps in workflow, L1 approval, L2 approval and finally posting data into SAP. When L1 or L2 clicks on Return button , then workitem routed back to Requestor and then restart workflow when Requestor clicks on Resubmit button. Let us configure workflow to fulfil this business scenario.

Open our custom scenario in Manage Workflow fiori app and click on + add button to create new workflow

Valid from and Valid to need to updated if we want to configure workflow for certain period of time else, leave it blank.

Configure steps. Click on Add in step sequence section and create new step.

Step1 – Level1 Approval

Choose Level1Approver Agent role in receipents. Pls note that these roles are coming from Agent Rules in Flexi block. So based on our business requirement, we have to create different rules to determine agents and use those rules in workflow step configuration.

Add Exception Handling actions as per our flow.

If approver Rejects – then workfow would get cancelled.

Returns  – Then workflow routed back to Requestor.

Note : I have used our other decision step To Requstor as required action for Return action and selected Restart workflow as action result. Due to this, When requstor clicks on Resubmit button, it will again routed back to L1 Approval for review and approval.

Similarly, add other 2 steps as well.

7.   My Inbox Task Configuration

Generally, we will activate task filter in real time scenario to display ONLY required workflow tasks work items in My Inbox App. So, unless we add these in Task settings, new decision tasks won’t be displayed in My Inbox app.

SPRO->SAP Netweaver -> SAP Gateway Service Enablement -> Content -> Workflow Settings -> Maintain Task Names and Decision Options

Sample Decision Keys for Return to Tequestor task, These desions will be displayed as buttons in My Inbox App.

Note: These are minimum steps needed to create one custom scenario and expose it to My inbox app. Let us start testing now.

8.   Testing

Login with requestor role and execute test method STARTWF in our workflow class.

Login fiori launchpad with Level 1 Approver  and check the work item in My Inbox app.

Click on Return button . As per our flow, it will be routed back to requestor.

Click on Resubmit, Workflow will restart again and work item goes to L1 Approver for approval.

Resubmitted by requestor and approved by L1. Workitem is awaiting final approval now.

Final L2 approver approved. As per flow, it called background activity and posted data and log updated and workflow got completed.

9.   Dead line Monitoring :

From S4 1909 onwards, SAP  has provided to enable dead line feature for decision taks steps in Manage workflow configuration.

As shown below , overdue item was triggered after 10 min and reflected that in SBWP and My Inbox app of L2 approver

10.   Email Templates

SAP provided Email template options to generate emails through flexible workflow scenario. Email template name plays main role while sending mail. We have to follow same naming convention as per our scenario to send email.

Copy Pre-delivered email template SWF_CRT_NOTIFY_RECIPIENTS and make changes as per your business requirement in custom template. When copying, you can name custom template as per your scenario correctly.

Naming Standards:

To send email before particular task id : YY1_(Scenario_ID)_CRT_(StepID)

For Ex : YY1-ZZ1_YY1_90000005_CRT_87 to send mail for L2 Approver

To send mail to requestor after completion of workflow with Approved or Rejection

Approve – YY1_(Scenario_ID)_COMPLETE_POSITIVE

Rejected – YY1_(Scenario_ID)_COMPLETE_NEGETIVE

Create one email template for L2 Approver as shown in below screenshot

L2 Email Template

Few Updates:

  1. When configuring ATO ( S_ATO_SETUP ) for in app enhancements, use prefix YY1_ , then we can able to create all email templates like for final approal (YY1_(Scenario_ID)_COMPLETE_POSITIVE)  or rejection (YY1_(Scenario_ID)_COMPLETE_NEGETIVE) as per SAP naming standards, Otherwise,it will not take that much name like ZZ1_YY1_*.
  2. If you want to enable dead line monitoring email notification in custom scenarios , then create that template in backend ( SWDD_SCENARIO) and then we will get email options in Manage workflow app.
  3. In above example, i have used seperate background task to update the data in to SAP . How ever, we can still wrtie this code in flexible workflow run time adopter class which is inherited from standard class -CL_SWF_FLEX_IFS_RUN_APPL_BASE. You can check this class in SWDD_SCENARIO – control tab of scnario definition.

FAQs

1. What are the different types of WF Agents?

1. Possible Agents:
a) Users who are authorized to execute the task
b) Configured during Task definition (Org Unit, Position, User, Work Center, Role, Rule)
c) If a Task is configured as General Task, then all users become possible users.

2. Responsible Agents:
a) The users to whom the work item needs to be sent.
b) This is set during Step definition. Note that Possible agents are defined during Task definition. (Org Unit, Position, User, Work Center, Role, Rule, Container Element) 

Note: The work item recipients are determined by the intersection of Possible Agents and Responsible Agents. 

3. Actual Agents: Actual user who executed the dialogue task

4. Excluded Agents: Users who are not supposed to execute the dialogue task (even if they are in possible agents)

2. What are the agent determination techniques?

  1. Rule Resolution with responsibility: Helpful when a set of static positions are responsible for an action.
  2. Rule resolution with Function (FM): Helpful when agents are determined dynamically from business logic.
  3. Rule resolution with OM: Usually used in CRM. Have not used
  4. Rule resolution with Function, but asynchronously: This is through a class and a method. Initially, WI is created in status ready without an agent. The later agent is assigned. This is suitable for agent determination having complex logic.

Users: Rarely used.

Role: Ex: ABAP_DEVELOPER

OM objects (Position, Org Unit, work center)

Expression: A container element containing the agents.

Containers
Workflow Container:
Task Container:
SWC_GET_CONTAINER
SWC_GET_TABLE
SWC_SET_CONTAINER
SWC_SET_TABLE
Event Container:
Method Container:
Rule Container: For resolving rules

Business Objects
Key Fields:
Attributes:
Database: Automatically gets populated by system code
Virtual: You determine the content and use SWC_SET_CONTAINER to populate
Methods: Can be created using FM, Transaction, Report, Dialog Module, Other
Synchronous: Finish execution before handling the control back to the task.
Asynchronous: Return the control back immediately. Cannot have export parameters. They depend on events to return results back to the calling program.
Dialogue: Something to user
Background: Cannot have messages or exceptions

3. What are the options to implement the method of a BO?

  1. FM
  2. BAPI
  3. Tcode
  4. Dialogue Module
  5. Report
  6. Other (BO program)

4. How to extend a BO?

1. Got SWO1 and enter a BO that you want to extend. Click on ‘New Subtype’ Give all the details.
2. Go back to SW01, enter the BO, and go to Settings Delegate.
Example:
BUS7051: Notification,
BUS1001: Material,
BUS2012: Purchase Order,
BUS1065: Employee

Various status of BO
Modeled: Not accessible at runtime
Implemented: Not ready to be used, Internal use only
Released: For the customer to use
Obsolete: Don’t use any more

To change attribute values from methods of a BO
SWC_GET_CONTAINER
SWC_SET_CONTAINER

5. How to create Events?

HR Tables: SWEHR2/3
ABAP Code user Exit: SWE_EVENT_CREATE
Change Document: SWEC
Status management:
Message Control:
Event Linkage: SWE2

Subtype: Key field cannot be created. Methods and attributes can be created.

Delegate: If you want to change the functionality of a method, define a subtype, redefine the method, delegate the parent business object to child object.

Interface: Interface is a combination of Attributes, Methods, and Events, to reduce the redundancy in the definition.

IFSAP: Common interface for all BOs. It has the following methods

Method: Display
Method: Existence Check
Attribute; ObjectType

  • Related Posts

    Attachments for SAP XI/PI – ARIBA Invoices sent via PI to S/4HANA

    Integration with SAP systems has never been more intriguing, especially with Ariba, Workday, Concur, Successfactors, Fieldglass, Hybris, and other satellite cloud solution vendors banging on doors every day. 🙂 I…

    11 Steps to Include a New Field in an Already-Existing SAP LSMW Batch Input Recording

    Alright. Why in the world do we care about LSMW in this paper when S/4HANA migration cockpit should ideally replace it? 🔥🎥 The simple answer is that not all people…

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    You Missed

    SAP XI/PI – Invoice Attachment Transfer from ARIBA to VIM

    • By Varad
    • November 8, 2024
    • 2 views
    SAP XI/PI – Invoice Attachment Transfer from ARIBA to VIM

    11 Steps to Include a New Field in an Already-Existing SAP LSMW Batch Input Recording

    • By Varad
    • November 6, 2024
    • 2 views

    Part 23 of ABAP for SAP HANA. How Can AMDP Be Used to Access Database Schema Dynamically?

    • By Varad
    • November 4, 2024
    • 2 views

    S/4HANA VDM 1 Employing CDS Virtual Data Model for Embedded Analytics

    • By Varad
    • November 1, 2024
    • 5 views