0% found this document useful (0 votes)
910 views

Workflow Basic Config and Concepts

Workflow is a business process automation tool that ensures the right work is sent to the right person at the right time. It is used to route documents and transactions through approval processes. Key aspects of workflow include: - Links transactions together in a defined sequence - Identifies the next step and responsible employee - Communicates with employees in their language - Monitors transactions and sends reminders if there are delays

Uploaded by

Jai
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
910 views

Workflow Basic Config and Concepts

Workflow is a business process automation tool that ensures the right work is sent to the right person at the right time. It is used to route documents and transactions through approval processes. Key aspects of workflow include: - Links transactions together in a defined sequence - Identifies the next step and responsible employee - Communicates with employees in their language - Monitors transactions and sends reminders if there are delays

Uploaded by

Jai
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 87

Workflow

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.

Work flow is business process automation tool


 WF links the transactions
 WF identifies the next transaction to be executed.
 WF identifies Employee responsible dynamically.
 WF communicates in the employee language.
Benefit Delay done by employees can be reduced.

T-code PFTC - Task: Maintain.

T-Code PFTC is an important transaction in SAP WORKFLOW concept.


This transaction is to create the WORFLOW Template and Standard Task which explained in depth going
forward.
Workflow Architecture:

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.

T-code: SWO1 Business object builder.


Here we can develop events, purpose of event is to start the workflow and pass the data to workflow.
Event related transactions:
SWEL: Display event trays. (Monitors weather event is triggered or not.)
SWELS: Switch on the trays.
Connection between Event and workflow can be done in transaction SWDD or PFTC
This connection is also called as subscription; workflow is going to subscribe that event.
Then the Function module ‘SWE_EVENT_CREATE’ will publish that event.

Connections between Event and WF can be monitored from SWETYPV


All the workflows connections can be monitored from this transaction.

Connection between Event and WF is Many to Many relationship.


Types of Workflows:

Type 1:Client independent WF (Workflow Template)


Type2: Client dependant WF which is obsolete (Workflow Task) ‘Out dated’.

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

Methods develops in a transaction SWO1

Step: Every node in WF is called as step


Steps can be one line of ABAP code.
Call to a methodimp
Call to another workflow (Sub WF)

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

RSWUWFML2: Create notification Email.


RSCONN01: Send Notification to outlook inbox.

Naming Convention (Numbering) :

Standard task TS <3 digit prefix> <5 digit sequence number>


Customer task T<3 digit prefix> <5 digit sequence number>
Workflow Template WS<3 digit prefix> <5 digit sequence number>
Workflow task WF<3 digit prefix> <5 digit sequence number>
Task group TG<3 digit prefix> <5 digit sequence number>

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.

RFC Destination configuration:


WF engine execution is client specific it requires RFC destination to be configured in the system to
execute the workflow.

Step 1:
Step 2: A pop up will display RFC destination

RFC Destination : WORKFLOW_LOCAL_<Current client>

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.

Note: this setting is to be done in DEV, QUL, PRD clients. (Mandatory).

GOTO SM59
Step1:
For WF we need to go with Logical connections.

Step2:

Here connection type L Logical Destination which is used for Workflows.


As WF is client dependent no sever details are required.

Logon and Security details are required.


To check User go to SU01

Give user name WF-BATCH and display.


Go to tab logon data.

User type is system (Background).

In address tab we need to maintain Mail id as in below screen.

If not maintained mails will not go out.


Note:
 Password is required for this user WF-BATCH by default system will not generate password for WF-
BATCH.
 Assign a password using SU01 can take help of basis team.
Steps should follow in basic configuration of WF:

Step1: Generate Configure RFC destination using T-code (SWU3).


System creates
 WF-BATCH user (WF-BATCH)
 RFC Destination (WORKFLOW_LOCAL_<Current client>)
Step2: Assign Password to WF-BATCH (SU01),
Assign Email ID to user.
Note: sometimes user will be locked, IF locked follow step 3

Step 3: Unlock the user WF-BATCH if locked using (SU01)

Step 4: Delete RFC Destination –Using SM59

Step 5: Regenerate setting using Step 1 (SWU3).

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.

Error: *********** Password Synchronization failed************

Reasons: Either password in SU01 AND SM59 is different or passwords are not maintained in SU01/SM59.

Assigning Workflow Administrator:

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:

We have 4 types of agents :


 Possible agents
 Permitted agents
 Excluded agents
 Selected 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:

Generic Decision Task TS00008267 General Task.

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:

Click on Create agent assignment button for assigning limited agents.


The agents’ types are given below.
Agent type T-code to search for the type
Work Center CR03
Role PFCG
JOB PPOCE
ORGUNIT PPOCE
POSITION PPOCE
TASK PFTC
USER SU01

Maintain Time Units


Go to SWU3
Step 1:

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.

Example: online Examination.


Let’s say Exam start on day 1st Jan 2014 time 9.00 AM and end at 1st Jan 2014 time 12PM.

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

Schedule back ground job for work items with errors.

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.

When the job reruns background jobs the WF also restarts.


This is automatic process, we don’t have provision to change the data or check the inputs given to the
methods, so to change the data we need to opt for manual restart using SWPR T-code.

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.

Schedule background job for the condition evaluations


This setting is used to evaluate the conditions to be checked by the system.
For example some conditions require process of waiting for time period and valuate conditions.
Example auto time card approval. Time card will be auto approved if no action takes by the respective
person in time.

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.

Standard job : RSWUWFML2 (for creating notification emails)


Notification mails: emails that are created in the outlook for every mail (work item) in sap In-box.
Notification emails will have same subject and body text similar to sap inbox mail (work item).
Work item: mail created in sap inbox by default is called work item.

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.

Open the standard program (RSWUWFML2) in SE38.

Step 1:
Step 2:

Step 3:
Step 4:

Once the variant created go to SM36 Transaction

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:

And follow the same process of RSWUWFML2 background scheduling process.


Creating Business object:

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.

Key field created:


EVENT:
Step1:

Step 2:

Give the Event, Name and Description and click on continue.


METHOD:

Step 1:

Select method and click on create.


A pop-up box will be display, which asks us weather to create the Method using existing FM as template,
Click on No as we are trying to creating the new method.

Step 2:

Enter the Method, Method name and description.


Check the Dialog check box, which indicates that method executes foreground.
Check the Synchronous check box, which indicates that system wait for the complete method execution,
I.e. system waits till results are received from the diff work processes.
Click on continue button.

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

In above code snippet SET PRAMETER ID ’BES’ FIELD OBJECT-KEY-VBELN.


Here we need to pas parameter id of VBELN of t-code ME23.
For that we need to check in technical details of the VBELN of screen ME23 as below.
OBJECT-KEY-VBELN.
Here OBJECT Is main structure included the method as part of template, Key is sub structure and
VBELN is field in KEY structure.
Thorough this code we are trying to set the VBELN value to call transaction ME23.

CALL TRANSACTION ‘ME23’ AND SKIP FIRST SCREEN.

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.

Create one more method (Background).


Create the program.
Another method UPDATE_DOCUMENT will be created in the same program ZPO_BO001.
Now in this method we can use update technologies BDC, etc...
Example:

Save and check syntax errors.

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.

In the above screen implies that respective object is released.


Here methods and events are not released, follow the below process

And same process to change the status from IMPLEMENTED to RELEASED.

NOTE: individually we need to release each method.

Same applies to event.


Step 1: Creation of BO Event is done.
Step 2: Creation of BADI.

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

Step 2: create custom implementation for the BADI

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:

To trigger Event we use FM: “SWE_EVENT_CREATE”.

For this FM important Export parameters are


OBJTYPE = 'ZPO_BO001'  Object type that we create in SWO1
OBJKEY = Declare local variable using the type mentioned in the FM for this field.
EVENT = 'TR_EVENT'  Event that we create in Business object.
DEBUG_FLAG = 'X'  purpose of this flag is to activate debugger which is used to
debug any validation return before starting the workflow.
Benefit of this flag is, internally data base commit is made for the newly created event.

Code snippet:

SIGNATURE: signature is Import Export parameters for a method.

Save and activate once logic implemented.


Go back to main screen and activate the implementation.
Work Flow:

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.

Click on insert variable button

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.

Go to properties tab and check the parameter settings.


Go back to BASIC DATA tab and click on insert variable button, select variable to be inserted and press
enter.

Once we press enter the variable will be inserted in the work item text as below.

By this numbering concept is possible to the workflow.

Save the task in the package and click on WORKFLOW BUILDER.


SWDD:

Click on Go to button  Basic data


Start event tab will tell that which event will start your workflow.

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.

In this case EVENT memory is parent (Idle).


Workflow memory is child, so WF should decide what data should exchange to parent.
Or we can also click on generate auto binding button.

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 1select 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.

If the condition set here is not satisfied WF will not start.

Few more scenarios where WF will not start.


 WF will not start if Condition not satisfied.
 WF will not start if connection is not active.
 WF will not start if WF is not active.
 WF will not start if RFC destination is not configured in SWU3.
 In some cases WF will start and stops in next second, because of Schedule Background Job for
condition Evaluation is not configured in the SWU3.

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.

Step 3: Decision Options

Decision texts: is for push buttons for decisions.


Outcome Name: these are output paths, which are branches of WF.

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.

Benefit of Secondary method:


In some scenarios we not only call transactions but also displays the attachment along with transaction, if
suppose the related software which can displays attachment is not available on your system, so secondary
methods will create new session to display the documents in spite of stopping the WF with error.

Assign Methods which we created in Business object:


Step :1 Go to METHODS tab give the business object and method in business object.
Step 2: CONTROL tab click on STANDARD TASK (TS000008267)

Step 3:

The core business logic will be seen in the methods of PROCESS.

Double click on PROCESS to see the methods.


Creating the STANDARD Task to link the Method of Business object and assigning to Approve or Reject
actions.

Approve action:
Go to PFTC Transaction.
Select the STANTARD TASK type, Click on create.

Give the abbreviation, Name.


Select the object category BO BOR Object Type
Give the Object type.
Give the method in Object type.

If the method is background, task should also background.


Check the Check box of BACKGROUND PROCESSING and click on save.

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.

Click on define binding Automatically button .


A pop-up will displays which asks that, binding process to do automatic or not?
First let’s accept, system will some required automatic bindings, then you can correct as per your
requirement by click on binding button.

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.

Double click in Workflow container to create new element.

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.

Once we maintain everything related to Mail. Click on Transfer button.

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.

Click on Binding button in the Control tab.


Now mapping have to be done from TASK to WF because Actual agent will be involved in the TASK.

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.

Inserting a reason text :


To insert the reason text we need to create a method in business object with two parameters

Step 1: Create method in BUSINESS OBJECT:

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.

Step 2 : create parameters.

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.

Declarations for FM: SAP_WAPI_READ_CONTAINER


DATA: RETURN_CODE LIKE SY-SUBRC,
IFS_XML_CONTAINER TYPE XSTRING,
IFS_XML_CONTAINER_SCHEMA TYPE XSTRING,
SIMPLE_CONTAINER TYPE STANDARD TABLE OF SWR_CONT,
MESSAGE_LINES TYPE STANDARD TABLE OF SWR_MESSAG,
MESSAGE_STRUCT LIKE TABLE OF SWR_MSTRUC,
SUBCONTAINER_BOR_OBJECTS TYPE STANDARD TABLE OF SWR_CONT,
SUBCONTAINER_ALL_OBJECTS TYPE STANDARD TABLE OF SWR_CONT,
LV_WA_REASON LIKE LINE OF SUBCONTAINER_ALL_OBJECTS.
Declarations for FM: SO_DOCUMENT_READ_API1
DATA: DOCUMENT_ID LIKE SOFOLENTI1-DOC_ID,
OBJECT_CONTENT LIKE SOLISTI1 OCCURS 0.
Declarations for Business logic:
DATA: LV_NO_ATT LIKE SY-INDEX.

Logic:

IF RETURN_CODE = 0.
*** Initialize count to 0.
LV_NO_ATT = 0.

*** Read the _ATTACH_OBJECTS element


LOOP AT SUBCONTAINER_ALL_OBJECTS INTO LV_WA_REASON
WHERE ELEMENT = '_ATTACH_OBJECTS'.
LV_NO_ATT = LV_NO_ATT + 1.
DOCUMENT_ID = LV_WA_REASON-VALUE.
ENDLOOP.

*** Read SOFM document.


CLEAR: OBJECT_CONTENT.
CALL FUNCTION 'SO_DOCUMENT_READ_API1'
EXPORTING
DOCUMENT_ID = DOCUMENT_ID
TABLES
OBJECT_CONTENT = OBJECT_CONTENT.
* Pass the text to the exporting parameter
IF SY-SUBRC = 0.
READ TABLE OBJECT_CONTENT INTO RSN_TXT INDEX 1.
SHIFT RSN_TXT BY 5 PLACES LEFT.
SWC_SET_ELEMENT CONTAINER 'RSN_TXT' RSN_TXT.
ENDIF.
ENDIF.

Once the Method is ready, create a new step in between user decision step and send mail step.

Assign the method in task and follow the below bindings.

Workflow  task binding.


&_PREDECESSOR_WI.WORKITEMID&  contains the previous work item ID.
Map to &WI_ID& created in the task level.
Task Workflow.
&RSN_TXT&&RSN_TXT&.

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.

Creating the Rule for agent determination.

Rule is used to determine the agent with the logic.


How to use the Rule, how we bind the rule with the WF?

Rule creation: T-code (PFAC)


Step1: Go to PFAC transaction and click on create.

Step 2:
Step 3: Go to SE37 transaction to create Function group and function module.

Create function group, example ZRULE_FG.


Create function module under FG, example ZRULE_FM.

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

Go to tables tab and create above table parameters.

And activate.

Step 4: Link the FM name in Rule and save the rule.


Once the rule saved in package, Rule no will be generated for your rule automatically as mentioned in
above screen.
In our example Rule no is: 999000001 RULE_TEST.

Step 5: give the rule no in step as in below screen.

And click on transfer button.

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.

Create data elements: ZAPPROVER TYPE CHAR14


ZMANAGER TYPE CHAR14

Create custom table with following fields: ZRULE_TABLE


APPROVER TYPE ZAPPROVER
MANAGER TYPE ZMANAGER
FROM_DATE TYPE BEGDA
TO_DATE TYPE ENDDA

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:

Step2: In pop-up screen.

You might also like