Вы находитесь на странице: 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 object
SYSTEM.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 agents
existing 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 of
its 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 methods
by 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 delegation
type 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


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 I
have 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 agents
custom table.A result table is returned containing all the agents fetched as per the
selection criteria.
This method GET_EMAIL is used to fetch the email addresses of the selected agents
from the custom table.This method also returns a result table containing all the email
addresses.
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
Container elements used in the workflow are as follows :
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”
This step “Describe Agents” returns back the number of agents available.We are
capturing this information into the workflow container variables &AGENTS and
&NUMOFAGENTS.
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 purpose
standard SYSTEM BOR object method LOOPATAGENTS is used.
Set the conditions of looping in the condition editor of the “Agents Loop” loop step.The
loop will continue till the number of agents becomes equal to zero as shown below.
Get the Email Address in the "GetEmail" step.
Send the mail to the Agents got in the previous step.
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 loop
condition does not happen.

Вам также может понравиться