Workflow Basic Config and Concepts
Workflow Basic Config and Concepts
What is workflow?
Work flow is business process automation tool, which ensures that the right work is sent to the right person at the right
time in the right sequence with the right information.
Work flow is used for document approvals.
Workflow is a flow chart of transactions and these transactions can be foreground or background.
Workflow is used for monitoring transactions, for sending remainder mails, for escalations for any delay.
When creator executes the transaction the respective BADI or user exit will execute in background we use
the below highlighted function modules in BADI/ USER exit by passing the required information to the
Function modules to trigger the Workflow.
Function module: ‘SWE_EVENT_CREATE’ or ‘SAP_WAPI_CREATE_EVENT’
The exact function of the function modules is to trigger the Event, when event triggers the associated
Workflow will trigger automatically.
TASK
Standard task and customer task both are used to call methods.
Difference is Standard task is client independent which is obsolete, Customer task is client dependent and
Task can be created by T-code PFTC
Task can be called Foreground as well as background.
IF task is executed in foreground we need to pass following things.
Object
Method
Email subject
Email Body text
POSIBBLE agents Note: Employee given at workflow level were PERMITED agents.
Possible agents are used when standard task used without workflow, Permitted agents are dynamically
determined based on current scenario like current document, current company code etc.
Note: Permitted agent must be possible agent.
IF task is executed in background we need to pass following things.
Object
Method
Method
Steps can be executed by system (Background) or user (Foreground). Based on the logic written in the
methods we can decide whether step is foreground/background.
While creating methods we have checkbox to select foreground or background.
Similarly TASK’s.
Email.
By default mail will redirected to SAP In box if we want to send mails to outlook we need to schedule 2
standard programs in SM36
Example: TS30000001 here TS is naming convention 300 is current client 00001 is sequence
no.
Note: 3 digit prefix is DEV client, 5 digit Sequence no will be generated by system in sequence Ex.
00001, 00002…etc.
We need to configure 3 digit prefix using T-code SWU3
Go to SWU3 (Automatic workflow customizations)
Follow the below path
Step 1:
Step 2:
Step 3:
In above pop up screen we need to enter prefix number 9 series is recommended and save.
Note:
Customizing prefix is not required in quality and in production, we need to configure only
one time in development system.
Make sure that this prefix is not used for other clients.
Step 1:
Step 2: A pop up will display RFC destination
System creates this RFC destination when we click generate button in below screen
This RFC destination is used by WF Engine or WF runtime system to Execute WF, Reason is WF
engine execution is client specific so it requires RFC destination.
GOTO SM59
Step1:
For WF we need to go with Logical connections.
Step2:
Note:
when we regenerate system will not create background user, because user is already available in
system
System creates RFC destination
System uses the password from su01 and assign in SM59.
IF we not follow the above 5 steps the below error will be raised.
Reasons: Either password in SU01 AND SM59 is different or passwords are not maintained in SU01/SM59.
Go to SWU3 t-code.
In popup box we need to give user id of the person who is acting as administrator.
Sometimes we have group of user to be assigned then we need to choose other option in dropdown and
save the entry.
Even thought workflow administrator will have administrator tools, having access to those tools is not
sufficient his user id should also exist in the settings then only he can act as administrator.
AGENTS:
Possible agents:
Possible agents will be declared in the standard task or customer task, this task can be used independently
without WF like IDOC’s, Reports… ETC.
Permitted agents:
Agents declared in the workflow were called as permitted agents.
Excluded agents: ( Excluded agent is a Permitted agent but not possible agent)
In the above M4 is treated as Excluded agent, As per the rule”Permitted agent should be a possible agent”.
This process is also known as automatic exclusion. Using Business logic also we can manually exclude
agents, this process is known as manual Exclusion.
Selected agents:
Permitted agents – Excluded agents = Selected agents.
(M1 M2 M3 M4) – (M3 M4) = M1 M2.
From resultant agents only one agent is actual agent, M1 or M2 or Administrator.
Maintain active plan version
Go to SWU3
Step1 :
Step 2:
Give the active and current plan version and save it.
Plan version determines the organizational structure in the organization, It will changes according to
the changes happen in organizational structure with new responsibilities and time.
The latest organization structure is considered with the plan version, this plan version will be used
WF to determine the agent, If we give wrong plan version the agent will pick up from older visions or
wrong organizational structure.
Note: For the implementation projects the latest and current plan version will be 01, for support projects it
might different.
We can see this HR Organizational structure of current Plan Version in PPOS transaction
Classify Decision Task as General
Go to SWU3
Step 1:
Step 2:
This Standard Task is system generated which is used during decision making approvals like accept or
reject.
All most all the standard workflows use this task for the decision making.
This task no will be same in all the systems like FI, HR, MM, and SD…. Etc.
Step 3:
With this customizing setting we used to assignee all agents at the task level using “General task”.
All the users in the sense FI, HR, MM, SD…. Etc. all the agents in the different systems will be set as
POSSIBLE agents
So General task is a standard task with all the users in the srever are possible agents.
But in some of scenarios it is not recommended to use General task, the reason is as follows.
As per the above scenario the mail will be triggered to every possible agent, as a result 1000 agents will
receive the mail.
Error Trouble shoot for the above case is
Write logic like if permitted agents are not found, at least Redirect mail to WF Admin.
At least maintain Error contact table so that in error cast we can send the mail to error contacts
which were maintained in the table.
Copy the task to a new number and assign only required agents.
Maintaining only limited agents:
Step 2:
All the units will be maintained in the units of measurements.
Work flow system uses only the units which are present in these settings, if the units are not maintained
the results will be calculates wrong.
TAG = DAYS
WCK= WEEKS
Mostly these two units are used in WF calculations we can do the days and week’s calculations.
We can use function module ‘END_TIME_DETERMINE’ to calculate the days and weeks.
These calculations mainly used to send the remainder mails.
Schedule background job for the missed deadlines.
Before starting this setting we need to know concept Deadline monitoring Events.
Deadline Monitoring Events.
4 types of deadline monitoring events.
1. Requested start
2. Latest start
3. Requested end
4. Latest end
To know about these events lets use a small example of online examination.
First event Requested Start will send work item (Email) to the agent with the question sheet on 1st Jan
2014 time 9.00AM
Second event Latest Start will send reminder mail to start the exam if it is not started yet on 1st Jan 2014
time 9.30 Am
Note: This Event send reminder mail if the no action taken place in the given time interval, based on the
status, IF the status changes to in progress or started the mail will not send.
Third event Requested End this is also sends remainder email to complete the task on time.
Note: this event will not trigger if the task is already complete.
Fourth event Latest End this is also remainder to complete or it will notify time is over and please submit
the assigned task.
After these four events we need to decide whether to give more time or not, with the logic. The above
events job is to send remainders mail only.
Let’s say we have 100 workflows which are going to send mails like above, If all the above events of 100
workflow triggers at a time. There will be the drastic increased amount of burden on the server.
As a solution we have standard job SWWDHEX which is going to trigger events in periodic intervals by the
setting Schedule background job for the missed deadlines.
Go to SWU3
Step 1:
Step2:
Once we enter the frequency and click on save and schedule the job will be scheduled in sm37
automatically. And executes the events for every 3 minutes.
Go to SWU3
This setting is to restart automatically if any background steps (Background methods) went into error.
Step 1:
Step 2:
Once we save and schedule the standard job, Job SWWERRE will be scheduled in sm36 and reruns the
background methods which went wrong.
For manual restart of the background methods which went wrong, we have T-code (SWPR).
Once after finding the error background methods, give the respective task no and workflow work item
details and execute
Here we have provision to check and change the data and restart the workflow.
For this evaluation we have standard job available in the system JOB: SWWCOND.
We have 5 standard jobs to be scheduled in background in WF.
T-code to use Job name Description
SWU3 SWWDHEX Dead line monitoring events
SWU3 SWWERRE Restarting work items (WF)
SWU3 SWWCOND For Condition Evaluations
SM36 RSWUWFML2 For creating notification mails
SM36 RSCONN01 For sending emails from server to external email box
Note: first 3 Jobs will be scheduled from SWU3 T-code and other 2 jobs will be scheduled from SM36.
These emails will have attachments to activate sap GUI and go to sap inbox.
Two attachments will be sending with mail.
1st attachment:
When we double click on 1st attachment it will ask for USER/PWD and activate SAP GUI and goes to SAP
inbox (SBWP) T-code.
Benefit of first attachment is we can see all the mails present in sap inbox and process any work item
2nd attachment:
When we double click on second attachment, it will ask for USER/PWD and their by activate sap GUI, and
mail goes to sap inbox (SBWP).
And it will also open/Execute the scenario related work item.
Benefit of 2nd attachment is method automatically called when we double click on the 2nd attachment.
Transaction/ABAP code will be executed.
1st screen of transaction will be shown for the processing.
We feel that, from outlook we perform sap activities.
To schedule the job RSWUWFML2 in SM36 to send notification emails, first we need to create the Variant in
the ABAP editor SE38.
Step 1:
Step 2:
Step 3:
Step 4:
Give the JOB Name and click on Step button in the menu.
Step 5:
Step 6:
Step7:
Select Other period in the pop up screen.
Step 8:
Select minutes from the popup screen and give the time. And click on save.
Click on the save button in the previous 4 screens or click on save button on 4 screens.
Once the job scheduled the above message will be displayed in the bottom of the screen.
SSCONN01 (For sending emails from server to external email box.)
To schedule this job SAP was given variant already.
Lets directly go to SM36 and give the job name and click on STEP
Step 3:
In the above flow diagram we are now creating Business object Event and Business object Method.
Go to SWO1 (Business object builder).
Step 1: Go to transaction SWO1 and give the business object name according to the naming conventions
followed in your project and click on create.
Step 2:
Here object type is Business object name which we given in previous screen.
Object name can be anything, once we enter the program name here system will create the program
template with this name where some basic declarations and code will be created, Application is type of
application for which we are implementing the Business object, in this example we are creating the BO for
the material management (M).
We can select the application type from the dropdown.
After giving the inputs in the above mentioned screen click on continue button and save it in the package.
Once the object success fully created and saved in package the below screen will be displayed.
KEY FIELDS:
Place the cursor on the Key fields and click on create, Then the below pop-up will be displayed which
asks us for create the key fields with ABAP dictionary field proposals?
Click on YES.
In Pop-up box give the Header table or main table and press enter.
Once we press enter it will display all the primary keys present in that table.
Chose the required primary key and click on Continue button.
Note: this Selected primary key will be act as primary key of business object.
Key field in the above screen will be populate by the system automatically for our coding comfort change it
to technical name as below, and click on create.
Step 2:
Step 1:
Step 2:
Step 3:
Select the method and click on Program then Below pup will be displayed, which asks us for
Below pup will be displayed
Which informs us that Method not yet implemented and do you want to generate a template
automatically for the missing section? Click on Yes.
Then it will create a template with basic declarations and code as below, if we click on no we need
to create the same by our own.
Example: Let’s write small straight forward code in BEGIN_METHOD and END_METHOD
Skip first screen will skip the first screen of ME23 and displays the document of respective id in the
next screen.
I.e. the below screen will be skip and next screen will be displayed automatically.
FIRST SCREEN.
SECOND SCREEN.
Once the code is syntactically correct change the status of BUSINESS OBJECT from MODELED to
IMPLEMENTED, Then IMPLEMENTED to RELEASED by following process.
Step 1:
Go back to main screen of business object builder, give the object name and follow the below path to
change the status MODELED to IMPLEMENTED.
After implemented do the same process for change the status from IMPLEMENTED to RELEASED.
Note: IF code contains any syntax errors the status will not change.
Once the status changed to RELEASED, status will be reflects in the BO status as released.
Once BO status change to Released click on generate button.(Similar like activate button)
Whenever we do changes to activate BO we need to click on GENERATE button.
Creation of BADI:
Note: BADI should trigger at the end of transaction process.
Example BADI: ME_PURCHDOC_POSTED which triggers on creation of document(ME21)
Go to SE18.
Step 1:
In interface tab interface name will be displayed and the methods which defined in the interface will be
displayed.
Now we need to create child class which inherits parent class properties. Then method POSTED will be
inherited in to child class.
Note: We can create multiple child classes, which represents multiple implementations.
BADI’s supports multiple implementations
USER EXITS supports only one implementations
In pop-up box give the custom name to your implementation and click on continue.
Once we click on continue, in the next screen we need to give description to the custom implementation.
Custom Class will be auto generate based on parent class.
Save the implementation in the PACKAGE.
Double click on the method To edit the code; once we double click it will take us to ABAP editor.
Example code:
Code snippet:
Go to T-code PFTC
Select WORKFLOW Template from the dropdown.
Step 1:
Note:
Every WF will have on unique number, so rather number is used as search criteria to search WF we
use ABBRIVATION mentioned here.
Name is static description.
Work item text is Instance specific description.
Instance one work flow instance generated for one document, if we create 10 documents 10 WF’s will
started.
Insert variable concept is used to identify the right workflow, so this is useful during analysis.
To insert any variable first we need to create the INSTANCE OF BO TYPE in container tab.
Note: don’t forget to check the parameter settings in the properties tab, if forgot the created variable will
not be displayed in the list to insert the parameter in the work item text.
Once we press enter the variable will be inserted in the work item text as below.
Once the first column converted into green color which implies that it is active.
Click on binding in second column.
Binding:
Binding is process of mapping variables in between 2 memories.
Purpose of binding is to pass data or get data between EVENT and WORK FLOW.
In the binding panel Event will be on left hand side and work flow will be on right hand side
In these 2 memories one memory will act as parent memory and other memory will act as child memory.
At any time child memory should decide what it requires from parent and what it would like to send it to
parent.
Parent memory will be Idle.
Note: If any variable which we created in WF are not appeared in the list.
In the left hand side we have small button click on that and choose workflow container.
Select the container element from the list and check the parameter settings in the properties tab and click
on continue.
CONDITIONS:
Conditions which we set here is for evaluated before starting the workflow.
Click on CONDITION button in third column.
Step 1: Express 1select the container element from the top right side block these container
elements are from EVENT.
Step 2: Select the condition operator from the operators block.
Step 3: Express 2 We can give constant value as in above screen or we can pass another variable.
Step 4: Check the condition for consistency (Ctrl+F2), and click on Transfer condition (F3)
Note: These conditions are mostly used in Standard WF; In custom WF we used to give conditions in BADI
or USER Exit.
Workflow Layout:
Step 1:
Step 2: Select User Decision step and click on continue.
Step 1: Title.
Give title EX: ‘Please Approve or Reject PO’.
If you want to pass any dynamic values in Title like “Please approve or reject PO<PO no>”,
We need to give &1 or &2 or &3 or &4 in the Title box where ever you want to display dynamic values.
&1 resembles value of PARAMETER 1
&2 resembles value of PARAMETER 2
&3 resembles value of PARAMETER 3
&4 resembles value of PARAMETER 4
NOTE: we have only 4 parameters, if we want to display more parameters give only &1
In the title and create a variable ZTITLE and pass the required TEXT into it and give this element in
parameter 1.
Develop a background method that returns a title (100 chars).
Returned value should be assigned to WF container.
Use this returned value as title for the next step.
Step 2: Agents
Here we have to pass the agent, then that respective agent will act as Approver
Press F4 in Agents
Rule: To get the Agent from the Function module.
To develop the rule we have Transaction PFAC
User: we can directly assign user as above.
We do have other options like to assign JOB ID, ORG UNIT, and POSITION … e.t.c.
Note: These agents are also called as Permitted agents or Scenario specific Agents.
Methods:
we have 4
types of methods:
1: Before methods: these methods executes before WI Processing, we do the actions like Initialization,
Locking etc.
2: Task level Methods: These methods contain core business logic. These methods executes during WI
processing.
2.2: Secondary Methods: These methods create another session while executing the WF.
These methods executes during WI processing.
3: After Methods: these methods executes after the WI Processing, we do the actions like Unlocking,
Commit work and clearing objects.
Note:
Before and after methods will execute in main session at WF.
Secondary methods will execute in New Session.
Secondary methods and Task level methods will execute at once, if we close the separate session control
will again comes backs to Task level methods.
Step 3:
Approve action:
Go to PFTC Transaction.
Select the STANTARD TASK type, Click on create.
Now we need to assign this task to the respective branch (EX: Approved) in the layout of WF.
Assigning Task to Branch in WF layout:
Step 1:
Go to WSDD open the WF layout, right click on the required branch and click on create.
Note: whenever we want to call method we need to create Activity step type.
Select the activity step from the list and click on continue.
Step 2:
Give the task no, If not remember press F4, Give Business object type “ZPO_BO001”, Click on find and
select the task.
In above binding we are mapping business object from WF memory to TASK memory.
REJECT Action:
Step 1: Right Click on Reject branch and click on Create, select step from the list to send
the mail if the PO is rejected.
1. Expression
Expression is one type of selecting Agent, With Expression we can directly pass the
container elements, here &_WF_INITIATOR& is WF container element.
Apart from expression we can also chose some other options from dropdown and can pass the respective
details in the below mentioned format.
In the above given formats first letters (A, C, O, S & US) act as indicator to the data we provide.
2. Subject
Subject is text box; here we used to give subject of mail, We can also insert dynamic
values using INSERT Expression button and selects the required container element from the list.
3. Send Express Check box
If we check this check box, whenever we received this mail a POP-UP will be
displayed saying that you received a new mail, go to your inbox and check it.
4. Body text
In Body text actual message will be given, Here also we can insert the dynamic values.
Here in the above Body text example I have created new Workflow container element FINAL
APPROVER.
Select ABAP Dict. Reference radio button and choose structure WFSYST and field AGENT
To find the actual approver (Actual agent) for this WF.
Note: The Element which we create is only a variable, which has to be filling from the USER DECISION
step, because Actual agent involved in USER DECISION step to reject or approve the PO.
Note: As this field is created to receive data from child (Task) we need not to check Import or Export check
boxes in the properties tab.
Because here task will decide what to give and what to take from the WF, WF will be Idle so we just need
to create a static element to store the data.
System pop-up a screen which asks for Abbreviation and name to create the TASK.
Give the Abbreviation and Name and click on continue to save it in package.
System will create the task automatically with given abbreviation and name.
To check the TASK go to Control Tab.
Once the task is created go back to layout and double click on USER DECISION step to do the binding for
FINAL APPROVAR.
Drag and drop _WI_ACTUAL_AGENT from Task Container elements and FINAL_APPROVER from
Workflow Container elements.
_WI_ACTUAL_AGENT will be available in every foreground step.
Here mapping is done from User decision Task to WF and WF to Send Mail Task.
Once after binding is done in User decision step, go to Send mail step, Double click on TASK created by
system in Control tab and check the following check points.
And check Final approver is mapped from WF to Send mail task Container element by clicking on binding
button.
Note: Don’t click on PROGRAM button to generate the template before creating the parameters to the
method, if we create program before we create parameters the template will not generate the required
signature and related code in the program.
Best practice :
Step 1: Create the method.
Step 2: Create the parameters.
Step 3: Crate program.
If we follow this process the template will be generated with the right signature, and required IMPORT and
EXPORT related statements will be generated automatically using set and get statements.
Create parameter : RSN_TXT (to capture the reason text given in previous step and to insert in mail body
of next step)
Create Parameter: WI_ID (to import the Work item ID)
Once the 2 parameters created successfully select program and click on program
Once we click on PROGRAM the below pop-up will displays , which asks about to generate a template with
this method automatically , click on yes.
The below method will create automatically.
In the above code snippet the code highlighted with hash color will be generated automatically.
If the parameter is created as import the below statement will be auto generated.
SWC_GET_ELEMENT CONTAINER ‘<PARAMETER NAME>’ <PARAMETER NAME>.
Example: SWC_GET_ELEMENT CONTAINER 'WI_ID' WI_ID.
If the parameter is created as Export the below statement will be auto generated.
SWC_SET_ELEMENT CONTAINER ‘<PARAMETER NAME>’ <PARAMETER NAME>.
Example: SWC_SET_ELEMENT CONTAINER 'RSN_TXT' RSN_TXT.
We need to call 2 Function modules one after other to read the reason text and display in mail body.
FM: SAP_WAPI_READ_CONTAINER
Use: The container of a work item is read (in a simplified form).The parameter
WORKITEM_ID specifies the work item for which the container is to be read.
FM: SO_DOCUMENT_READ_API1
Use: This function module provides all information on a document.
Logic:
IF RETURN_CODE = 0.
*** Initialize count to 0.
LV_NO_ATT = 0.
Once the Method is ready, create a new step in between user decision step and send mail step.
Note: RSN_TXT will be created automatically once we click on Define binding Autom
After assigning task to the STEP.
Step 4:
Go to send mail step and insert the Element RSN_TXT in the body of mail using Insert Expression button.
Step 2:
Step 3: Go to SE37 transaction to create Function group and function module.
Note: The below mentioned 2 table parameters are mandatory to create the FM for creating rule.
Parameters Names should also be same as given in below table which is highlighted in red, if parameters
given with some other names mapping will not be done properly.
PARAMETER ASSOCIATED TYPE Properties
ACTOR_TAB SWHACTOR EXPORT
AC_CONTAINER SWCONT IMPORT
And activate.
Step 6: Now we need to create the required logic in the FM to determine the Agent.
For this requirement we need to create the dictionary elements in SE11.
Go to SE11 and create the Data elements and custom table with the above mentioned properties and
maintain entries manually.
Step 7: Go to container tab of RULE and create the key field and save it.
Step 9: now go to workflow go to user decision step, once the rule and respective rule no is given Click on
binding button to bind the memories between WF memories to Rule memory.
Step 8: Go to function module source code and write the logic as shown in the below screen shot.
We can execute the RULE directly from PFAC transaction by clicking on simulate rule resolution button in
Rule.
Step 1: