Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Mithun_Sharma
Explorer
0 Kudos
590

Title

A method to send concurrent workflow work items to a dynamic number of business users.

Introduction

In this blog, we will discuss the process of sending concurrent workflow work items using a sub-workflow to a dynamic number of business users instead of using a fork.

A Business Workflow is used to automate various custom and standard business processes, such as an approval process, notification process, and other business requirements.

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 is used to determine a responsible agent or agents. There are various rule resolution techniques such as rule resolution with responsibility, rule resolution with function, rule resolution with organization management, and 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 is used to segregate the business logic into class methods and define 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 ( Tcode - VA01)  and identify the underlying business object, which is BUS 2032 in this case.

Image Description: Sales Order Creation - VA01Image Description: Sales Order Creation - VA01

Image Description: Sales Order CreatedImage Description: Sales Order Created

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

Image Description: Main WorkflowImage Description: Main Workflow

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

Image Description: ZCL_WF_SO Class-methodsImage Description: ZCL_WF_SO Class-methods

Methods:

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

Step 4. Create a decision task that will send a decision work item to the workflow initiator.

Image Description: Decision taskImage 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 TaskImage Description: TRIGGER_SUBWORKFLOW Task

a) The GET_AGENT method is used to determine the responsible agents from the TVARV table

Image Description: TVARV Table Entries for AgentsImage Description: TVARV Table Entries for Agents

b) We now pass the determined agents to a sub-workflow, which will be called multiple times, depending upon the number of agents determined, and generate concurrent dialog work items (VA03 Tcode) for them.

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

Image Description: Sub-workflowImage Description: Sub-workflow

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

Image Description: DISPLAY_SALES_ORDER TaskImage Description: DISPLAY_SALES_ORDER Task

Step 8. Following is the sample code for the determination of the 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.

* 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.
  ENDMETHOD.

 

Step 9. Execute the business case:

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

Image Description: Sales Order CreationImage Description: Sales Order Creation

Image Description: Sales Order CreatedImage Description: Sales Order Created

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

Image Description: Decision TaskImage Description: Decision Task

Image Description: Workflow WorkitemsImage 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. The task also triggers another workflow ( a sub-workflow) multiple times depending upon the number of agents determined and generates concurrent dialog work items (VA03 Tcode) for them.

Image Description: Workflow WorkitemsImage Description: Workflow Workitems

Conclusion

The blog helps design new business workflows for sending concurrent work items to a dynamic number of users instead of using a fork.

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:

https://answers.sap.com/tags/833755570260738661924709785639136

and read other posts on the topic:

https://blogs.sap.com/tags/833755570260738661924709785639136

Thank you.

Labels in this area