Skip to Content
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.
image 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.
image
image
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.
image
image
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.
image
image
image
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
image
image image
Container elements used in the workflow are as follows :
image
image
image
image
image
image
image
image
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”
image
image
image
This step “Describe Agents” returns back the number of agents available.We are capturing this information into the workflow container variables &AGENTS and &NUMOFAGENTS.
image
image
image
image
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.
image
image
image
image
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.
image
image
Get the Email Address in the “GetEmail” step.
image
image
image
image
Send the mail to the Agents got in the previous step.
image
image

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. image
This application be be further enhanced by connecting it to HR master tables and adding steps for updating HR data before the mail is sent to the respective agent.

To report this post you need to login first.

6 Comments

You must be Logged on to comment or reply to a post.

  1. David Halitsky
    Hi Ravi –

    This is a great post and one I’m sure will be helpful to me in the future.  (I’m taking BIT 600/601 in January.)

    But a question for you:  are the emails in your z-table for a given “agent” the same as the emails in adr6 for some “user”.

    Or are the agents not “users” in the usr01 sense?

    If agents = users, how come you decided to create a z-table instead of chasing the address numbers to adr 6?  Are the emails for “agent” users not in adr6 even though the agents are users in usr01?

    Please don’t get me wrong – I’m really hoping you’ll tell me why the agent emails
    CAN’T be in adr6. 

    Because then we’ll have the billionth example of why the Codd/Ellison paradigm is so impoverished as to be virtually useless once we’re above the level of a trivial organization like a bank or Health and Human Services.

    (0) 
    1. Ravi Shankar Rajan Post author
      Hi David
      Thanks for your comments.You are right in saying the emails can be in adr6 table.But What is been displayed in this blog is a sample version of the actual custom table.The actual table contains some company specific data based on which the emails along with the superior information is determined.The actual table fetches information based on some workflow rules created and is updated based on that.So based on the application rules executed the email addresses can be completely different from the agent.In this blog I wanted to keep things simple so that the basic concept can be understood without confusing the reader with too much details.
      (0) 
    2. Swathi Devireddy
      Hi Ravi,
      I dont understand why so many steps need to be there for this development.
      Why cant we have a simple background step to determine agents and populate it into a a multiline attribute and pass it back to workflow.
      And give the agent as Expression with the Multline Container.
      Hope i got ur requirement right
      (0) 
  2. soha pathan
    there is aquestion for you… I had a requirement where a approval is needed by contract managers for a creadit memo generated. In this case the contarct manager is derived from the person responsible field on WBS assighnemnt.so if there are multiple contract managers are found for multiple WBS elements then workflow should dynamically create a seperate approval for each manager. also subsequent approvals shuld escalate up an approval structure so that lower level operational approval is received before the higher level approval.Oce all approvals are finished then the billing block is deleted….

    i will use a WBS in my rule container , but how do i go thru the org structure of the contract manager(person respnsible  field) and his subsequent or superior levels? please suggest some idea.

    Thanks,
    Vineela.

    (0) 
  3. Nethaji babu
    Hi,
      This is Nethaji thankyou for your clear explanation. I think it is good to us if you do many
    more scenarioes
                                     Thanking you,
                                     N.Nethaji.
    (0) 
  4. Saurabh Chauhan
    Hi Ravi,
    Thanks for the elaborative blog. its really helpful. I copied steps by steps by what you have mentioned while creting this workflow, but for me it is not working. Its hangs at the place of selecting agents from ztable. When i tested my BO – ZSYSTEM and executed method GetAgents it showed an error –
    Message ID:          OL
    Message number:      831
    Access ‘C’ is not valid for the verb type ‘A’

    kindly help. I dont know where i am going wrong.

    Thanks

    Saurabh Chauhan

    (0) 

Leave a Reply