Technology Blog Posts by Members
cancel
Showing results for 
Search instead for 
Did you mean: 

Introduction

The blog describes the process of sending concurrent workflow work items using a sub-workflow for a dynamic number of business users instead of using a fork.

A Business Workflow automates various custom and standard business processes, such as an approval process, notification process, and others.

To do so, we need to identify the following objects:

1) A Business Object

2) A Workflow Rule for Agent Determination

3) A Workflow Task

4) A Workflow Class

Summary

A Business workflow consists of four major components: a business object, a workflow rule for agent determination, a workflow task, and a workflow class.

A business object: It consists of Interfaces, Key fields, Attributes, Methods, and Events

A workflow rule: It determines the responsible agents by applying an appropriate rule resolution technique. There are four rule resolution techniques: 1) Rule resolution with responsibility, 2) Rule resolution with function, 3) Rule resolution with organization management, and 4) Rule resolution with function asynchronously.

A workflow task: It consists of a class/business object method, container elements, bindings, and agents.

A workflow class: It segregates the business logic into class methods and defines events.

Step-by-step processes for creating a workflow for sending concurrent dialog work items to a dynamic number of users using a sub-workflow in a sales order creation process.

Step1. Create a sales order using Tcode - VA01 and identify the underlying business object, i.e. BUS 2032 in this case.

Image Description: Sales Order Creation - VA01

Image Description: Sales Order Created

Step 2. Create a workflow using SWDD Tcode and bind it with the business object BUS2032.

Image Description: Main Workflow

Step 3. Create a custom workflow class: ZCL_WF_SO and define the below methods:

Image Description: ZCL_WF_SO Class-methods

Methods:

  1. DISPLAY_SALES_ORDER:  It triggers a VA03 Transaction code to show the newly created sales order.
  2. TRIGGER_WF: It triggers a Sub Workflow.
  3. GET_AGENT: It determines the responsible agents from the TVARV table and triggers a sub-workflow using the TRIGGER_WF method.

Step 4. Create a decision task for sending a decision work item to the workflow initiator.

Image Description: Decision task

Step 5. Create a task TRIGGER_SUBWORKFLOW and bind it with the GET_AGENT method of the workflow class ZCL_WF_SO.

Image Description: TRIGGER_SUBWORKFLOW Task

a) The GET_AGENT method determines the responsible agents from the TVARV table

Image Description: TVARV Table Entries for Agents

b) The determined agents are now being passed to a sub-workflow. Thereafter, the sub-workflow is called in a loop, depending upon the number of agents, and generates a dialog work item of VA03 Tcode for every agent concurrently.

Step 6: Create a sub-workflow using SWDD Tcode and bind it with the workflow class ZCL_WF_SO.

Image Description: Sub-workflow

Step 7: Create a task DISPLAY_SALES_ORDER for displaying the sales order and bind it with the DISPLAY_SALES_ORDER method of ZCL_WF_SO.

Image Description: DISPLAY_SALES_ORDER Task

Step 8. Below is the sample code for determining the responsible agent.

 

* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_WF_SO=>GET_AGENT
* +-------------------------------------------------------------------------------------------------+
* | [--->] IM_INDEX                       TYPE        INT4(optional)
* | [--->] IM_VBELN                       TYPE        VBELN(optional)
* | [<---] EX_RC                          TYPE        INT4
* +--------------------------------------------------------------------------------------</SIGNATURE>
  METHOD get_agent.
*-------------------------------------------------------------*
* Get the workflow agent information
*-------------------------------------------------------------*
    DATA : lt_tvarv     TYPE STANDARD TABLE OF tvarv.
    DATA : lt_agents    TYPE ztt_agent.
    DATA : ls_agent     LIKE LINE OF lt_agents.
    DATA : lv_index     TYPE sy-index.
    DATA : lv_agent     TYPE swp_initia.
    DATA : lv_vbeln     TYPE vbeln.
    CONSTANTS: c_var1   TYPE rvari_vnam VALUE 'AGENT'.
    CONSTANTS: c_rc     TYPE int4 VALUE '1',
               c_agent(2) VALUE 'US'.

    FIELD-SYMBOLS: <lf_agents> LIKE LINE OF lt_agents.
    FIELD-SYMBOLS: <lf_tvarv>  LIKE LINE OF lt_tvarv.

  TRY.
* Get the workflow agents from the TVARV table.
    FREE: lt_tvarv[].
    SELECT name type numb sign low FROM tvarv
      INTO CORRESPONDING FIELDS OF TABLE lt_tvarv
                             WHERE name EQ c_var1.
    IF sy-subrc EQ 0.
      IF lt_tvarv[] IS NOT INITIAL.
        UNASSIGN <lf_tvarv>.
        FREE lt_agents[].
        LOOP AT lt_tvarv ASSIGNING <lf_tvarv>.
          CLEAR ls_agent.
          ls_agent = <lf_tvarv>-low.
          APPEND ls_agent TO lt_agents.
        ENDLOOP.
      ENDIF.
    ENDIF.

* Read the workflow agents and pass it to the sub-workflow
    IF lt_agents[] IS NOT INITIAL.
      CLEAR lv_index.
      lv_index = im_index.
      UNASSIGN <lf_agents>.
      CLEAR lv_agent.
      READ TABLE lt_agents ASSIGNING <lf_agents> INDEX lv_index.
      IF sy-subrc EQ 0.
        CONCATENATE c_agent <lf_agents> INTO lv_agent.
        IF sy-subrc EQ 0.
          CONDENSE lv_agent.
        ENDIF.
        CLEAR lv_vbeln.
        lv_vbeln = im_vbeln.
        IF ( lv_agent IS NOT INITIAL AND lv_vbeln IS NOT INITIAL ).
* Trigger the Sales order Display workflow
          zcl_wf_so=>trigger_wf( EXPORTING im_vbeln = im_vbeln
                                           im_agent = lv_agent ).
        ENDIF.
      ELSE.
        ex_rc = c_rc.
      ENDIF.
     ENDIF.
    CATCH cx_root.
   ENDTRY.
  ENDMETHOD.

 

Step 9. Execute the business case:

a) Create a new sales order using the transaction code VA01.

Image Description: Sales Order Creation

Image Description: Sales Order Created

b) The sales order has triggered the workflow and sent a decision work item to the workflow initiator.

Image Description: Decision Task

Image Description: Workflow Workitems

c) If the workflow initiator chooses "yes" from the decision work item, then a subsequent task (GET_AGENT) determines the responsible agents. Further, the task will trigger a sub-workflow in a loop depending upon the number of agents determined and generate a dialog work item of VA03 Tcode for every agent concurrently as shown below.

Image Description: Workflow Workitems

Conclusion

The blog helps design new business workflows on how to send concurrent work items for a dynamic number of business users.

I hope this article was insightful.

Any comments or suggestions will be appreciated.

 Please follow the following pages for SAP ABAP Development and post your answers & questions:

ABAP Development Environment Topic Page:

https://community.sap.com/topics/abap

Post and answer questions:

ABAP Development - SAP Community

Thank you.

Labels in this area