This Article Demonstrates How Agents Can Be Determined Dynamically in Workflow

Embed Size (px)

Citation preview

  • 8/8/2019 This Article Demonstrates How Agents Can Be Determined Dynamically in Workflow

    1/17

    This article demonstrates how agents can be determined dynamically in workflow.The

    agents along with their email addresses are stored in the custom table ZAGENTS.I have

    used a custom BOR object ZSYSTEM which is copied from the standard BOR objectSYSTEM.ZSYSTEM contains two new methods Get_Agents and Get_EMAIL

    which select the agent information along with their email addresses from

    ZAGENTS.Finally I have created a workflow which sends test mails to all the agentsexisting in ZAGENTS table.This can be further enhanced by updating the HR master

    tables in case of leave deductions or salary calculations.You can copy SYSTEM BOR

    Object into ZSYSTEM BOR object in two ways :Creating a subtype : A subtype of an object is another object whose creation is based

    upon a parent object . The subtype maintains references to all the attributes and methods

    of its parent object. This means that any methods and attributes defined on the parent can

    be executed and accessed on the child object. If a subtype object were merely a copy ofits parent, then all the code contained within the parent would be physically copied to the

    child. This is not the case. The subtype simply maintains references to its parents

    methods and attributes. The real difference is that the subtype lets you redefine these

    methods and attributes. You can easily add your own business rules to the parent methodsby redefining the subtypes method.

    Creating Object as delegation Type : In this case you define your own object and define it

    as a delegation type of the main object ie SYSTEM. In all definition tools you can still

    refer to the original object type, but the SAP System uses the definition of the delegationtype for every access. The delegation type must always be a subtype of the object type it

    is to replace. The delegation type can have different or additional methods, attributes, and

    events.The various objects involved in this workflow are as follows :

    Table : ZAGENTS

    This table stores the agent information along with their email addresses.Email addresses

    will be selected from this table.This table can also be connected to HR master tables as a

    further enhancement.

    BOR Object : ZSYSTEM : Copied from SYSTEM BOR Object

  • 8/8/2019 This Article Demonstrates How Agents Can Be Determined Dynamically in Workflow

    2/17

    This BOR object is ZSYSTEM is created as a subtype for the standard SAP BOR object

    SYSTEM.The SYSTEM BOR object contains some important utility methods for

    selecting agents,looping through agents and displaying agent information.In ZSYSTEM Ihave added some of my own methods to select data from the custom table.You can create

    ZSYSTEM from SYSTEM either by creating a subtype or by delegating.

    This method Get_Agents is used for fetching agent information from the agentscustom table.A result table is returned containing all the agents fetched as per the

    selection criteria.

  • 8/8/2019 This Article Demonstrates How Agents Can Be Determined Dynamically in Workflow

    3/17

    This method GET_EMAIL is used to fetch the email addresses of the selected agentsfrom the custom table.This method also returns a result table containing all the email

    addresses.

  • 8/8/2019 This Article Demonstrates How Agents Can Be Determined Dynamically in Workflow

    4/17

  • 8/8/2019 This Article Demonstrates How Agents Can Be Determined Dynamically in Workflow

    5/17

    Write the following code in the program section :

    BEGIN_METHOD GET_AGENTS CHANGING CONTAINER.types : begin of ty_agents,

    agent like wfsyst-agent,

    end of ty_agents.data : get_agents type standard table of ty_agents.

    select agent from zagents into corresponding fields

    of table GET_AGENTS.SWC_SET_TABLE CONTAINER RESULT GET_AGENTS.

    END_METHOD.

    BEGIN_METHOD GET_EMAIL CHANGING CONTAINER.

    DATA:ACTUALLYPROCBY TYPE WFSYST-ACT_AGENT,

    GET_EMAIL TYPE BAPIADDR3-E_MAIL,EMAIL LIKE ZAGENTS-E_MAIL.

    *Get the agent from the method container

    SWC_GET_ELEMENT CONTAINER 'ActuallyProcBy' ACTUALLYPROCBY.

    CLEAR EMAIL.select single e_mail from zagents into email

    where agent = ACTUALLYPROCBY.

    if not email is initial.GET_EMAIL = email.

    *Set the value of the email back to the result.

    SWC_SET_ELEMENT CONTAINER RESULT GET_EMAIL.endif.

    END_METHOD.

    WORKFLOW STEPS

    Using transaction SWDD (Workflow Builder ) we create a workflow

  • 8/8/2019 This Article Demonstrates How Agents Can Be Determined Dynamically in Workflow

    6/17

    Container elements used in the workflow are as follows :

  • 8/8/2019 This Article Demonstrates How Agents Can Be Determined Dynamically in Workflow

    7/17

  • 8/8/2019 This Article Demonstrates How Agents Can Be Determined Dynamically in Workflow

    8/17

  • 8/8/2019 This Article Demonstrates How Agents Can Be Determined Dynamically in Workflow

    9/17

  • 8/8/2019 This Article Demonstrates How Agents Can Be Determined Dynamically in Workflow

    10/17

    The workflow steps along with the tasks are as follows :

    This step Get Agents gets back the list of all the agents using the custom method

    Get_Agents

  • 8/8/2019 This Article Demonstrates How Agents Can Be Determined Dynamically in Workflow

    11/17

    This step Describe Agents returns back the number of agents available.We are

    capturing this information into the workflow container variables &AGENTS and

    &NUMOFAGENTS.

  • 8/8/2019 This Article Demonstrates How Agents Can Be Determined Dynamically in Workflow

    12/17

  • 8/8/2019 This Article Demonstrates How Agents Can Be Determined Dynamically in Workflow

    13/17

    This step Loop at agents to get agents loop at the Agents table and gets the current

    agent.The current agent is stored in the Agent container element.For this purposestandard SYSTEM BOR object method LOOPATAGENTS is used.

  • 8/8/2019 This Article Demonstrates How Agents Can Be Determined Dynamically in Workflow

    14/17

    Set the conditions of looping in the condition editor of the Agents Loop loop step.Theloop will continue till the number of agents becomes equal to zero as shown below.

  • 8/8/2019 This Article Demonstrates How Agents Can Be Determined Dynamically in Workflow

    15/17

    Get the Email Address in the "GetEmail" step.

  • 8/8/2019 This Article Demonstrates How Agents Can Be Determined Dynamically in Workflow

    16/17

    Send the mail to the Agents got in the previous step.

  • 8/8/2019 This Article Demonstrates How Agents Can Be Determined Dynamically in Workflow

    17/17

    After sending the mail to every agent as per the result decrement the agents in the loop

    using the Decrement Agents container step.This will ensure that endless loopcondition does not happen.