Está en la página 1de 831

SAP Business Workflow Tutorial

SAP Business Workflow


Tutorials ("How-to-do" documents):
Building a simple Workflow application using the steps "User Decision" and "Mail". (More details)
Including Custom text in the step "User Decision". (More details)
Creating a container element and using it in the step "Mail". (More details)
Inserting data from Internal Table into the step Send Mail (More details)NEW
Using "Condition" step (more details)
Using "Multiple Condition" step (more details)
Using "Container Operation" step (more details)
Demo on working with step "Loop (Until)" (More details)
Using the step "Form" in Workflow (Simple example) (More details)
Using the step "Form" (Detailed example) (More details)
Triggering Events Programmatically (more details)
Deadline Monitoring - Working with Latest end (more details)
Deadline Monitoring - Working with Requested Start (more details)
Dynamic Parallel Processing in Workflow (More details)
Personal Substitute for Workflow (More details)
Adoption of a Substitute (More details)
Notification of Work Items to an external email (More details)
Filtering the Work Items in the SAP Inbox (More details)
Adding Logo to the Work item preview (More details)
Tracing the events triggered during the execution of a transaction (More details)
Sending recursive mails upon reaching the deadline until the task is completed (More details)
Ad Hoc agent assignment in Workflow (More details)
Trigger a workflow to send an email whenever a material is created (More details)
Defining custom rules to use in Workflow definition (More details)
Maintaining Translations for the Work item text and Outcome Names (More details)
Raising exceptions in a method and handling the same in the workflow (More details)
ALE - Error handling through Workflow (More details)
Using ABAP Classes in Workflow (More details)
Using Document Template in Workflow (More details)
Demo on Workflow Wizard (More details)
Steps to transport agent assignment from one system to another (More details)
Creating rules using Responsibilities (More details)
Using the "Start Conditions" in Workflow (More details)
Using "Check Function Module" in Workflow (More details)
Retrieving the Work item details of the deleted users (More details)
Transporting Organization structure from one system to another (More details)
Configuring events for HR Workflow (More details)
Starting Workflow from Messages (More details)
Triggering Workflow using Business Transaction Events (More details)
Triggering of an event using Function Module Enhancement (More details)
Passing a hyperlink in a Work item (More details)
Working with Business Objects (More details)
To instantiate any Business object in a Workflow (More details)
Raising events based on changed document (More details)
Extended notification configuration (More details)
Debugging SAP events (More details)
Sending workflow notification to Requestor in HTML format (More details)
Registering WEB DYNPRO/BSP Application with a Workflow Work item (More details)
Working with Dynamic Task Submission in Workflow (More details)
Archiving SAP Work items (More details)
Delegate a Subtype to Supertype (More details)
Demo on Workflow using Classes (More details)
Sending multiple attachment in user decision step of workflow (More details)
Demo on working with Nested / SubWorkflows (More details)
Call instance method from workflow using class (More details)
Display Dynamic Attachments in Work Item in Workflow (More details)
Modify the run-time value of workflow containers (More details)
Capture Rejection Reason Text from User Decision in Workflow (More details)
Process a User Decision Programmatically at Background (More details)
Forward a work item to your own currently logged in SAP ID (More details)
Simplified Business Workplace Workflow Inbox in SAP R/3 (More details)
Program Exits in Work Item for Workflow (More details)
Consistency and Extended Checks for Workflow Template and Tasks (More details) NEW
How to Trigger Class based workflow? (More details) NEW
Offline Workflow Approval in ECC R/3 without SAP Logon from E-Mail (Outlook) (More
details) NEW
Passing multi-line parameters from an ABAP Class event to a Workflow container (More
details) NEW
Concept of Re-evaluate agents for active work items in SAP Workflow (More details) NEW
You might also be interested in:
Workflow Scenarios configuration:
Determine of release code of PO and PR (More details)
Purchase Order Release Strategy (More details)
Purchase Requisition Release Strategy (More details)
PO List Retrieval for which Workflow isn't triggered due to Event Linkage deactivation (More
details)
Triggering of events/Workflow upon status changes (More details)
Quality Notification Configuration (More details)
Triggering a Workflow whenever a PO is changed (More details)
Configuration of Leave request workflow for ESS/MSS (More details)
Display Workflow overview of one object (Purchase Order) in another (Purchase Requisition)
(More details)
Trigger workflow when a record is created in a database table (More details) NEW
Triggering approval workflows only for Purchase Orders belonging to a particular purchasing
group (using startup conditions) (More details) NEW
Advanced Features in SAP Workflow from version 6.40
Exception Handling in Workflow (more details)
SWITCH in "Multi-condition" step (more details)
Demo on "Local Workflow" (More details)
General information on Workflow
SAP Workflow customization settings (How to do) (More details) NEW
Transactions related to Workflow (More details)

Developing a simple application using steps "User Decision" and "Mail"
By Suresh Kumar Parvathaneni
Basic terminology used in the workflow:
The workflow definition is the set of rules that determine the path that the process takes. For example,
how a purchase requisition is processed, from the initial request to the creation of the purchase order
A Workflow Instance, which is often simply referred to as the workflow, is a single workflow run. For
example, the processing of a single purchase requisition for computers.
The Tasks are the steps in the process, which have to be performed either by people or automatically by
the software. For example, to check for the availability of the spare computers in the company.
A Work item is the task instance that is performed as a single workflow step. For example, check that
there are no spare computers available in the company.
Agents are the people who process the tasks (via the work items). For example, requisitioner and a
member of the purchasing department.
Container is the place where all the data used in the workflow is collected.
Binding is the set of rules that define which data is passed to which part of the process.
Building a simple workflow application
The central tool for creating, displaying and processing a workflow is the workflow builder (Transaction
SWDD). Within the workflow builder you can create all components of a workflow, including all the
containers you need for getting the data from one step to another.
Generally, most of the workflows are started by an event (for example, when a material is created or
when a new purchase requisition arrives). You define which data from this event needs to be passed to
the workflow via binding.
However you can also start any workflow directly. Let us create a simple workflow and start the workflow
directly, using the testing tools.
Call transaction SWDD. When the workflow builder is called for the first time, a newly created initial
workflow definition appears or else last created workflow appears. In such cases you can opt to
create a new workflow by pressing Create New Workflow(ctrl + shft + F5). The following screen
appears.

The initial workflow screen has the following parts:
a. The start of the workflow definition, indicated by .
b. The end of the workflow definition, indicated by .
c. The area in which you insert the new workflow definition is indicated by .
Now select the undefined step and select Create step or double click the undefined step. Now among
the different steps chose the User Decision by double clicking on it.


Developing a simple application using steps "User Decision" and "Mail"
Previous
Now enter the title for the user decision Please make a decision. Also enter the decision texts
as Approve and Reject. On pressing enter, the outcome values default to the Decision texts but you can
specify your own names, if desired. Now we need to select the agent. Agent is the person to whom the
work item needs to be sent.. Since this is just a beginning, we would hardcode the user name. Select
the User from the drop down list and enter the user name to whom the work item needs to be sent. In
general, this type of agent assignment is not done. Agents are generally assigned using the expression,
agent assignment rule or organization object (job, position etc.).

Now select Transfer and to graphic button. Following screen appears:

Now we need to include a mail step to be sent to the requestor. Now select the line Approve and do
a right click. Different options on shown on the context menu. Select Create.

Now select the step Send Mail from the list.


Developing a simple application using steps "User Decision" and "Mail"
...Previous
Now enter the subject and the body of the message for the mail to be sent.

Do not change the recipients. Our mail is intended for the persons who triggered this workflow.
&_WF_INITIATOR& contains the value who executed the workflow. Since this is a test object, we are
using &_WF_INITIATOR&. But we wouldnt be using this variable in real time scenarios. We would
discuss about this in the coming documents.
Now select Transfer and to graphic button.
A popup appears requesting for the abbreviation and the name for this task. Enter the same and
press enter.

Now enter the package as local object and press enter.
Follow the steps 5 through 9 for the step Reject. The following screen appears:

Press SAVE to save the workflow application. You need to enter an abbreviation and name for your
workflow as shown below. You can change any of these at any later point. After saving, a number is
assigned to your workflow starting with WS, as shown below.


Developing a simple application using steps "User Decision" and "Mail"
...Previous
To execute the workflow, activate it by choosing the activate button.
Test the workflow by choosing Test. The following screen appears.


Now choose Execute to start the workflow.
Now the recipient would receive a work item in his SAP inbox (Transaction SBWP).

Now execute the work item by pressing Execute. The following screen appears:

Choose one among Approve or Reject as part of the user decision. He can select the third option to
retain the work item in his inbox and make the decision later. Now suppose that the recipient has
chosen one of the first options. Now a mail would be sent to the requestor with the status of his
request.

Including custom text in the step "User Decision"
Whenever we create a step User Decision (For creation of User Decision step, click here) and provide
with our own options like approve or reject, the work item would appear as follows:

As marked in green in the above screenshot, the description available in the work item is a default one
provided by SAP. In case we need to add our own text, do the following:
1. Identify the task being used in the step User Decision.
In the step User Decision, click on the tab Control:

In the tab Control, the standard task that is being used is displayed. In this case, the standard task
that is being used is TS00008267.

2. Go to transaction PFTC_COP to copy the standard task. Select Standard task in the task type and
enter the task number (without the prefix TS) in the Task.

Click on Copy task.
3. Enter the abbreviation and the name as required.

Click on Copy Task.
4. Enter the package name as required.
5. A new task would be created. Please note the task number that is created now.
6. To change the task description, you can use the transaction PFTC.
7. Now go back to workflow definition, transaction SWDD.
8. Click on User decision and then click on the tab Control.
9. Here replace the standard task number with the custom task created above.
10. Do the agent assignment and generate the same.
It is always advisable not to change any of the standard texts. The change would reflect in all the
workflow definitions the task is being used.

Creating a Container element
By Suresh Kumar Parvathaneni
This document details about creation of a container element in workflow and using it in the step "Mail".
Pre-requisites:
It is assumed that the reader of this Tutorial is aware of creating a workflow definition with the step Mail.
If not, please go through the document on creating the same available, by clicking here.
Steps:
1. Create a workflow definition using the transaction SWDD.

2. Lets create a container element for Carrier id. Click on the Workflow Container on the left side of
the screen (as shown in the screenshot below):

3. Now double-click on Double-Click to Create

4. Enter the details pertaining to CARRID here.

5. Click on tab Properties and select Import.

6. Click on Confirm (Enter).
7. Now the element created could be seen on the left side, below the Workflow Container.


Creating a Container element
Previous
1. Create a Mail step by double-clicking on Undefined step in the workflow.

2. Enter the recipient details in the Recipients box.
3. In the subject line, enter Carrid value entered is: and click on Insert Expression.

4. Select the element Carrid from the list.


5. Similarly enter the content in the Body area.

6. Save and activate the application.
Testing the Workflow application:
7. Test the workflow by clicking F8.

8. Enter the value of the Carrid as shown above and press execute.
9. A mail would be sent to the recipient mentioned earlier with the carrid value entered.

Inserting data from Internal Table into the step "Send Mail"
By Sandeep Jape, Yash Technologies
Purpose: The purpose of this document is to insert multiple lines of an internal table in Send Mail Step
in workflow.
Business Scenario: This tutorial can be used wherever you need to insert multiple lines of an internal
table in Send Mail Step through workflow for example PR, PO rejection text.
Process: This demo creation will involve the following steps
Create custom workflow
Create container element
Fill Data in above created container element
Create Send Mail Step
Insert above container element in send mail step
Pre-requisites:
You should have the basic knowledge about workflow that how to create a workflow & how to
include Send Mail Step. (Please check other tutorials on SAPTechnical.COM for your reference)
Workflow configurations using SWU3 is already done
Step 1: Go to transaction SWDD, create a custom workflow save the same as follows


Step 2: Create a container element by name DIS_TXT& keep the properties as follows


Note: We are not going to fill this DIS_TXT at run time instead we will create test data in Initial Value
section which will be used at the time of testing. Refer the below screen shot, append lines using Append
Row Button & press confirm button >>

Step 3: Create add step Send Mail which will look like the following >>
Note:
Keep the Recipient as &_WF_INITIATOR&
Add subject & mail text & press OK button & give the name to step as follows & save in a request.

Now copy the task number of the send mail step & go to transaction PFTC >>


Inserting data from Internal Table into the step "Send Mail"
..Previous
Go to Transaction PFTC put your task & press change button >>

Now click on Container Tab & create an element as shown below >>

Note: Do not modify any standard mail step task, always copy & do the changes & use the same in your
custom WF.
Maintain properties for above element as shown below & save the task & exit >>

Step 4: Go back to workflow & send mail step >>
In mail step put your cursor on description & click o button Insert Expression
Double click on container element DIS_TXT & you will see following screen

Select last option All lines with line break. It will look like this
Note: For demo purpose I have included all 3 types

Press OK button & save the Workflow & activate
Step 5: Test the Workflow by pressing Test button as shown below

You will get following screen where press on execute button
Note: You can see the entries in container element DIS_TXT which we created earlier.

Now got to Transaction SBWP & click on Inbox & you will see our mail. Open it.

So we have successfully inserted multiple lines of an internal table in send mail step & displayed in
SBWP.
You can use this functionality in multitude of other ways as per your business requirement in your project.

Condition Step
By Suresh Kumar Parvathaneni
Agenda:
This document details about the steps Condition.
Pre-requisites: It is assumed that the reader of this document has a preliminary understanding of
workflow and has worked with the container elements earlier. If not, please go through the first two
Tutorials of workflow available in this site. (More details)
Procedure:
1. Create a new workflow definition.
2. Create a container element, CARRID (as demonstrated in tutorial 2).
3. Now click on undefined step and create the step Condition.

4. Enter the step name of your choice.
5. We would have the following condition here:
If carrid = AA.
Do this.
Else.
Do this.
Click on Click here to create a new condition. Following screen appears.

Double click on Carrid. Next click on = and enter the value AA in the constant field and press
ENTER.

Enter the outcome names of your choice as shown above.
Click on Transfer and go to graphic.

As shown above, there are two branches here. One navigates to true, if CARRID = AA else the
control takes the branch False.
Test the above scenario by inserting mail steps in the above 2 branches and by passing different
CARRID values.

Condition Step
By Suresh Kumar Parvathaneni
Agenda:
This document details about the steps Multiple Condition.
Pre-requisites: It is assumed that the reader of this document has a preliminary understanding of
workflow and has worked with the container elements earlier. If not, please go through the first two
Tutorials of workflow available in this site. (More details)
Procedure:
1. Create a new workflow definition.
2. Create a container element, CARRID (as demonstrated in tutorial 2).
3. Now click on undefined step and create the step Multiple Condition.

4. Enter the step name of your choice.
5. We would have the following condition here:
If carrid = AA.
Do this.
Elseif carrid = AH
DO this.
Elseif carrid = SQ
Do this.
Else.
Do this.

Select the CARRID using the F4 help for the comparison basis field.
Enter the values of the carrid under the Comparison values with the corresponding outcome name (of
your choice)

Double click on Carrid. Next click on = and enter the value AA in the constant field and press
ENTER.
Click on Transfer and go to graphic.

As observed above, there are different branches for each value of CARRID mentioned above.
Test the above scenario by inserting mail steps in all the branches and by passing different CARRID
values.

Using "Container Operation" step
By Suresh Kumar Parvathaneni
Agenda: Usage of step Container Operation.
Pre-requisites: It is assumed that the reader of this tutorial has worked in the concepts that are dealt in
earlier tutorials. (click here for more details)
Scenario: In this tutorial, we would deal about how to work with the step Container Operation with an
example of calculating the available seats by subtracting occupied seats from themaximum seats at the
workflow level.
Procedure:
1. Create a new workflow definition using the transaction SWDD.
2. Create two container elements MaxSeats, Occ_Seats with the import property set. You can use the
reference fields sflight-seatsmax, sflight-seatsocc for this.


3. Create another container element AvailableSeats without setting either import or export property as
this is calculated within the workflow and used within the workflow. You might use any of the above
reference fields as data types.

4. Define a new step Container Operation in the workflow definition by double-clicking on the
Undefined step.

5. In this step, we would calculate the available seats from the max seats and seats occupied.

I would recommend entering all the container elements from the F4 help instead of typing them
manually.
6. Return to the main screen.

7. Create a mail step after this to send the available seats information.

8. Test the above functionality by passing some values to the maximum and the seats occupied.
9. Result would be as follows:


Demo on working with step "Loop (Until)"
By Avinash Palavai, StraVis IT Solutions
Prerequisite : Should have basic idea of worklow and usage of container elements, container
operation and Send Mail Steps.
1) Go to the t.code SWDD ( Workflow Builder ). By default, it opens the last developed workflow. So
click on create to create a new Workflow. Below screen appears.

2) Double click the below shown item in the workflow container to create an element called Counter.

3) Then the below screen pops up and fill the screen as shown below,


4) Now create a step Loop (Until).



5) Now the following screen of step Loop Until opens and set the condition as below, i.e. the loop runs
until

6) Now your workflow appears as below,


Demo on working with step "Loop (Until)"
...Previous
7) Then create a Send Mail step on the False branch of step Loop Until as shown below,

8) Enter the following details in Send Mail step and click on Transfer and to graphic .

9) Give an abbreviation and name to the Task.

10) Now your workflow would look like below,

11) Then create a Container operation step on the same False branch of step Loop Until after
the Send Mail step.

12) Build the below condition, to increment the counter element.

13) Now your workflow appears as below,

14) Save and activate the entire workflow and test it .
15) Click on in the below screen,

16) Go to your Business workplace (SBWP) and check the inbox. You will find two mails, as the counter
is initially set to 1 and loop runs for two times until Counter gets incremented to 3 to satisfy the
condition that was set in container operation.


Using the step "Form" in workflow
By Saumik Bhattacharya, Capgemini
Form is an important step type of workflow builder. We can use forms to enter data for processing in
Business Workflow, or to display and edit data.
Using the Forms step type we can generate a form from the workflow system with a structure that is
saved in workflow container. This form can be used for displaying and editing the form data. It can also
contain additional control elements that can be used, for example, for the approval of form content.
First of all we are creating a workflow container element in transaction code SWDD. You can use a form
to display or edit data of a container element of the workflow container that refers to a structure.
The element should be of type reference to an ABAP dictionary.

Then we will insert the forms in workflow:

Here we have to insert form type and action. Action can be of four types:

For it you have to create a form so that you can attach it to the workflow. Click on create button:


Here we are creating the form named Material info using the workflow container element Y_form_makt.

Now according to our requirement we are just using the material number & material description in the
form layout.
For e.g. we are using the material number as input value and description field as output only.

We have also implemented the required changes in the flow logic of that form.


Finally we had attach two mail on approve and on reject.

After completing this, we will execute this workflow and will get the form:

We will go for approve this form and we will get description

And here is the approved mail:


Using the step "Form" in workflow
By Sai Kumar B, Enteg Infotech
In the need of input from the user other than mere clicking of accept and reject actions, we can use the
Form Step in workflow. The form step presents the user a form (User interface) thus by enabling the
workflow developer to capture the required input from the user. The form used here is just like classic
Dynpro screen, which can be designed in Screen Painter (SE51).
To Begin with lets start with Workflow builder, SWDD. In this tutorial I was just showing how to include a
form step inside a workflow.

1. Right click on the activity and select create.

2. Select the form step type.

3. In the next screen provide Step Name and agent assignment
4. Select the form type and action
5. Then click on Create (Before clicking on Create make sure that you have declared a structure in
container which can be used as the structure for the form / Screen you are going to include.

6. If you have not created the structure, you can do so by double clicking the container.

7. Then give name for the container element and type of the element, and if you are using this
structure for changing of some values be sure to check export and import check boxes in
properties tab.

8. Coming back to the form step click on the create button.

9. This will start a wizard, Click on continue

10. Give your form a name and select the structure for which you are building the form .
11. And click on continue.

12. Then click on complete

13. Save the object


Using the step "Form" in workflow
...Previous
14. Now you can change the form as per your need. You can use the form as it is, as the logic will be
handled automatically. The changes that were made in the form at runtime will directly reflected in
the container element. If you need more complex logic you can modify the form as per your
requirements by clicking on change button.

15. This will open the form in screen painter to modify the form, make necessary changes in layout.

16. If you need to change the flow logic you can go there by clicking on flow logic, where you can
change the flow logic.

17. If you want to control the data in PBO and PAI level you can double click the module to be
navigated to the function modules generated by sap system. Even though SAP recommends not
to change the modules you can change them with due caution to meet your requirements.



Finally activate everything and test.

Triggering Events Programmatically
By Suresh Kumar Parvathaneni
Purpose: This document details the procedure in triggering the business object events programmatically.
Pre-requisites: It is assumed that the reader of this document is aware of the business object concepts
and good in ABAP.
Procedure:
In this document, we would take an example of the business object BUS1001006 (Material) and the event
CREATED. In general, this event is triggered whenever a material is created using a standard procedure
like MM01 or any others. Now we would trigger this event from our own programs.
Following are the screenshots of the business object BUS1001006 and the event CREATED. Go to
transaction SWO1 for more information of the business object.

Double-clicking on the key field parameter gives you technical information of the field.

In order to trigger an event programmatically, we would use the function module
SWE_EVENT_CREATE.
Following is the sample code to trigger the events programmatically:

REPORT ZDEMO_TRIGGER_EVENT.

DATA: KEY LIKE SWEINSTCOU-OBJKEY.

KEY = '1163'. Material Number (hard-coded)

CALL FUNCTION 'SWE_EVENT_CREATE'
EXPORTING
objtype = 'BUS1001006'
objkey = KEY
event = 'CREATED'
* CREATOR = ' '
* TAKE_WORKITEM_REQUESTER = ' '
* START_WITH_DELAY = ' '
* START_RECFB_SYNCHRON = ' '
* NO_COMMIT_FOR_QUEUE = ' '
* DEBUG_FLAG = ' '
* NO_LOGGING = ' '
* IDENT =
* IMPORTING
* EVENT_ID =
* TABLES
* EVENT_CONTAINER =
EXCEPTIONS
OBJTYPE_NOT_FOUND = 1
OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSE.
WRITE 'Event Triggered'.
ENDIF.

COMMIT WORK.
In order to test whether the event is getting triggered or not, we can make use of Event Trace. Switch on
the event trace using the transaction SWELS.

Press Switch On.
Now execute the program developed earlier. Now switch-off the event trace using the same transaction
SWELS.
Now go to transaction SWEL. Here you can list out the events triggered in the particular period of time.
Here is the event-trace list:



Deadline Monitoring in SAP Workflow (Working with Latest end)
By Suresh Kumar Parvathaneni
A major advantage of workflow is the ability to monitor the workflow steps according to a predefined
schedule. Following are different deadlines that can be monitored against each workflow step:
Requested Start
Latest Start
Requested End
Latest End
In this example, we will define a deadline to the User Decision example created earlier (click here).
Following is the screenshot of the application developed using the User Decision example:

We would extend this example to the deadline monitoring.
In the User Decision step, click on the latest end tab.

By default, No deadline monitoring is active (as seen in the above screenshot).
Choose the Work Item Creation from the list box.

After selecting Work Item Creation, chose an offset of 5 minutes. This means that the work item must be
executed within 5 minutes of the creation, if not this would trigger.


Deadline Monitoring in SAP Workflow
...Continued
Enter recipient details to whom the message to be escalated, if the work item is not executed with in 5
minutes after work item creation.

Save and activate the workflow definition.
Testing the workflow application:
Execute your workflow.
Check for the work item in the SAP Inbox. This time do NOT execute the work item.
Wait for the deadline to be triggered. After that, a deadline message is delivered to the recipient
mentioned in the Latest End tab. See the screenshot below.

Dont worry if the deadline message doesnt appear immediately after 5 minutes. This depends on
various factors including how the deadline monitoring program is scheduled and also on the availability of
the background processors.
Use SWWA to check how the deadline monitoring program is scheduled in program.

For example, assume that our work item has been created at 09:10 hrs and the deadline message is
expected to trigger at 09:15 hrs. From the above screenshot, it is understood that the background
program is scheduled to execute for every 3 minutes. Assume that the last run of the program is at
09:14hrs and the next run is expected at 09:17hrs. So even our deadline expires at 09:15, the deadline
message would appear only at 09:17hrs after execution of the background program.
Some more points
In our above example, we have used the deadline on the Work Item creation time. i.e., 5 minutes after
creation time, the deadline message would be sent. Now we would check the other option Expression.
Here we can mention the date and time, when the deadline message should appear irrespective of the
work item creation date/time.

As seen in the above screenshot, we can provide the target date and time by which the task should be
finished. Container elements could be used in this case. Please refer to our example on creation of
container elements (click here).

Deadline Monitoring in SAP Workflow (Working with Requested Start)
By Ravi Aswani
In this tutorial, we would look into implementation of Requested Start in the step User Decision. This is
common for the step Activity and others as well.
Go to transaction SWDD and create a step User Decision. Click on the tab Requested Start.

For demo purpose, we would be choosing the Requested Start as 2 minutes from the work item creation.
Choose the Work Item Creation from the list box.

Choose an offset of 2 minutes. This means that the work item shall be created after 2 minutes.
Save and activate the workflow definition. Execute the workflow definition.
In SAP inbox, you can observe that the work item is not yet delivered.
Following is the status of the workflow instance. You can observe that the work item is in the status
Waiting.

The status of the work item would convert to Ready after 2 minutes (as per the time mentioned in the
Requested Start).



Dynamic Parallel Processing in Workflow
By Punit Jhanwar, YASH Technologies
This blog is a step-by-step approach for using dynamic parallel processing in Workflow (For the concept
of dynamic parallel processing, please click here).
For our demo purpose, we have taken a simple example. A multiline element Material is passed on to
workflow and our step Activity has to be executed n times (n denotes the number of materials in the
multiline container element Material). In simple words, if 10 materials are passed to the workflow, then
10 work items are to be generated. Following is the step-by-step approach in achieving the same:
1. Create workflow using the workflow builder.

2. Create a Multiline container element for Material number .


3. Create a step Activity in the workflow definition.


4. Click on the tab Miscellaneous.

In the field Multiline Element, click on F4 and select MATNR.


5. Now go back to the tab Control. From the list box, select Create task

Enter the abbreviation and name for the task.

6. Let us have the material number displayed in the work item text. For this, we need to create a container
element for the Material (not a multiline element).



Dynamic Parallel Processing in Workflow
...Previous
In the properties, click on Import.

7. Insert the container element MATNR in the work item text .

8. Choose the business object and the corresponding method for the material display (we have chosen a
dummy method for our demo purpose).

Click on Save and come back to the main screen of step Activity.

9. Define the binding between the activity and the task.

As seen in the above screenshot, there are two MATNR in the workflow container. One representing the
multiline element that we have created for the workflow container and the other is an index of a MATNR.
Since we have defined MATNR for the dynamic parallel processing, this step Activity would execute for
each entry in this multiline element MATNR. So MATNR() represents the index of the material during
runtime.
10. Choose the User in the Agents and specify the user id.

11 . Activate the workflow .

12. Execute the workflow. Test run your workflow definition by providing some test data


13. Now check your SAP inbox (Transaction SWBP). There would be three work items for three materials.


Personal Substitute in Workflow
By Suresh Kumar Parvathaneni
Requirement: Need to have at least one substitute who can act upon work items in your absence.
Important: The appointed substitute would be able to see all your work items. A substitute cannot be
assigned for only particular area of organization or any other item. So need to ensure that the substitute
have the necessary authorizations to act upon the work items.
Procedure:
1. Go to SAP Business Work Place (TCode: SBWP)
2. Now from the menu bar, select Settings Workflow settings Maintain Substitute


3. Highlight/Select the name on the window, in this case SAPDEV02 and click on Create
Substitute.
4. List of users available in the system are displayed.

5. Select the required substitute user name. Following screen appears.

Validity field describes about the period in which the setting would be active. Note that the dates on
the screen would range from the current date to 31
st
Dec 9999.
Regarding the checkbox Substitution active, it is advised to leave this checkbox unchecked for
system performance reasons. A check in this box indicates that the substitution is permanent and if
left unchecked it is treated as as-needed. A permanent substitute will automatically receive the
primary users work items in their own box. In the case of as-needed, substitute must manually adopt
the work items from the primary users inbox.
6. Save the entries

7. Click Enter to leave the screen.
For information on how to adopt a substitution, click here.

Adopting a Substitute in Workflow
By Suresh Kumar Parvathaneni
If you have been designated as an as-needed substitute, you must manually adopt the substitution. If
you are designated as a permanent substitute, the work items would automatically appear in the inbox.
Before adopting a substitution, there are 19 work items in the inbox. See the screenshot below:

To adopt a substitution, select Settings Workflow settings adopt substitution.

Select the corresponding User-id (if you have been assigned as a substitute for multiple people, then this
option would allow you to select the user name of whom you would to check the work items)

The corresponding users work items would appear in our inbox now.

You can end the substitution, by selecting settings Workflow settings End substitution.
Note: Substitutes can only adopt work items that are directly routed to the person for whom they are a
substitute. If you are a substitute for a user (SAPDEV02) who has been made a substitute for another
user (SAPDEV01), you will only see work items for user SAPDEV02 and not of the user SAPDEV01.

Notification of Work Items via e-Mail
By Suresh Kumar Parvathaneni
SAP provides us with a facility of notifying the user via the email address of your choice when there are
any pending work items in the SAP Inbox..
1. Go to Transaction SO13.

2. Click on Automatic Forwarding tab.

3. Click on Create icon .

4. Enter the details in the above screen.

5. Click ENTER to complete the entries.
6. Now the notification would be received at the provided email address if there are any pending work
items in the inbox.
Filtering the Work Items in the SAP Inbox using BADI
This document details about the procedure in filtering some of the work items from the SAP inbox using a
BADi.
Following is the screenshot of the SAP inbox, before implementing BADi:

The BADi that is used in filtering the work items is WF_BWP_SELECT_FILTER. To implement the BADi,
go to transaction SE18. From the menu, select Implementation Create. (See the screenshot below)

Enter the implementation name and press ENTER

Enter any meaningful short text for the implementation and click on the tab Interface

The implementing class, ZCL_IM_BWP_SELECT_FILTER, is automatically proposed. Double click on the
implementing class name.

You are now navigated to the class builder. Now double-click on the method name shown on the screen
(see the snapshot below)

Now let us filter out the work items belonging to the task TS2000066. See the code below:

Activate the method and also the implementation. In the state of active, you wouldnt be able to make any
changes. To make any changes, we need to deactivate it and then make the changes.

Now check the inbox and would notice that the work items related to that task are no more appearing.

To notice the differences, try activating and deactivating the BADi implementation.

Inserting the logo in the Work item preview
To upload the logo:
1. Go to transaction SMW0
2. Select Binary data for Web RFC applications.

3. Execute the transaction (No need to fill any values on the selection
screen)


4. Click on Create. The following screen appears. Enter the Obj. Name and
Descriotion.
5. Click on import. Select your company logo.
6. Your entry is now available in the table control on the
screen.

Embedding this logo in the Work item preview
1. Create a workflow definition with a simple step User decision.
2. Now in the step User decision, go to tab Work item
display.

3. Click on Demo Function
Modules.

The function modules shown above need to be used as a template for defining the logo as per the
requirement. Using the function module SWL0_PREVIEW_DEMO_GIF_ONLY, we can only display the
logo of the company. Using SWL0_PREVIEW_DEMO_TEXT_AND_GIF, we can display both logo and
our own text below the logo. The FM SWL0_PREVIEW_DEMO_TEXT_ONLY is used to display custom
text only. For our demo purpose, we would use the FM SWL0_PREVIEW_DEMO_TEXT_AND_GIF.

Inserting the logo in the Work item preview
Previous
5. Copy the function module SWL0_PREVIEW_DEMO_TEXT_AND_GIF to a Z function module.


6. Now change value of e_info-gif-id to the object-id created in SMW0 (Logo id) and e_info-
dialogtext to the custom text we require.

Save and activate the function module.
7. Now in the workflow builder and in the tab Work item display, mention the name of the Z function
module created
earlier.

8. Execute your workflow definition. In your SAP inbox, you can see the logo and the custom text in the
preview pane of the work
item.


Tracing the events executed in a transaction
By Suresh Kumar Parvathaneni
In the article triggering events programmatically, we learned about triggering the events
programmatically in our custom programs. But SAP has already provided with many events in almost all
the standard SAP transactions like:
1. When a material is created, a standard event is triggered
2. When a Purchase Order is created, an event is triggered.
3. When the status of a production order is changed, an event is triggered.
We can link the events to either standard workflows or custom workflows to carry out our business
requirements. Before linking the business workflows to events, we would need to trace the events that are
triggered in a transaction. This document explains the procedure in tracing the events for the Material
Master transaction (MM01). We would trace the events that are triggered when a Material is created using
MM01.
1. Go to transaction SWELS. A pop-up screen as shown below would
appear:
2. Click on Switch on. The event trace would be on
now.
3. Keeping this event trace on, create a material using MM01.
4. Now go to transaction SWELS and click on Switch Off to switch off the event
trace.
5. Go to transaction SWEL to get the list of events triggered during the Material
creation.

6. Click on
Execute.

The list of events that are triggered are shaded in green. A workflow object (shown in yellow) is also
triggered as it is attached to the event CREATED belonging to the business object BUS1001006.

Sending recursive mails upon reaching the deadline until the task is
completed
Recently, we encountered a scenario where-in we need to send recursive mails for every xx hours, when
the deadline is reached, until the task is completed. I am presenting the same here, with a simple
example, hoping that this would be useful to you all.
Start a new workflow and define a "User Decision" step. For steps on how to define a User Decision
step, click here.
In the step "User Decision", switch to tab "Latest End" and provide the details as shown below:

In the action, select "Modeled" from the list. Enter the name of the outcome.

Click on "Transfer and to Graphic" (Green tick button).

You can notice that there are 3 branches now. Two belong to the User Decision Step (YES/NO) and the
other one is of Modeled deadline. So whenever a deadline is reached, this branch executes. When the
user completes his task, it would either take YES or NO branch accordingly.
Now assume that we need to send repetitive mails to the agent for every 3 minutes, until he completes
the task (in this case, acting on User Decision step).
Double-click on "Undefined step" in the "Modeled" branch and select LOOP(Until)

Using "Loop (Until)", we would be sending emails repetitively for every 3 minutes. To keep the loop open
continuously, lets define a condition which would never be met.
Enter a step name and then click on "Click here to create a new condition".

Since we intend to make this Loop indefinite, create a condition similar to the following one.

Now go back to the main screen.

The above screenshot is of the step "Loop (Until)". Now double-click on the "Undefined" step above and
create an email step.

Enter the recipient name and other details as shown above.
....To continue click here

Sending recursive mails upon reaching the deadline until the task is
completed
...Previous
Now we need to send mails once every three minutes until the task is finished. To achieve this, we would
need to create a business object (or use an existing one) and create a dummy method (with no code in
it). Ensure that the check box "dialog" is unchecked in the properties of this method.

Now create a step "Activity" by double-clicking on undefined step after the email step in the Modeled
branch.

Click on "Create new task"

Provide the details as shown below:

Don't forget to check the checkbox "Background processing".
SAVE and click on Back button.
In the activity step, switch to "Requested start" tab and provide details as shown below:

Using the above step, we are restricting the LOOP to send mails for every 3 minutes only.
Save and activate your workflow.
Test run the workflow. Do NOT execute the work item and wait for the alert mails.
Work item in inbox:

Work item along with the alert mails (after the deadline is reached):


Ad Hoc agent assignment in Workflow
By Sathis Kumar R, Quintegra Solutions
This Article is about the Adhoc Agent Assignment for workflow. The workflow initiator assigns a recipient
to the steps in the workflow at runtime.
Scenario:
Assigning Adhoc Agent for the task " create the leave form".
Step by step:
Create the new workflow named as "wf_4adhoc "

Drag and drop the activity from the step type.

Now create a new task for leave form.
In that give your own abbreviation and name for the task.
Object Category : BOR Object
Object Type : FORMABSENC.
Method : CREATE.

Now save the task and go back .Now the binding between the task and the workflow was shown like.

Click ok (Tick mark) button.
Now the task complete option was active.

You don't fill any agent for this task. You leave it as empty as shown in the figure.
Now we move to the Task properties. Click the agent assignment icon.
Click here to continue...

Ad Hoc agent assignment in Workflow
....Previous

Now choose the task and click the attributes button.

Choose the General Task and click the Transfer button.

You go back to the workflow builder now the Agent Assignment was active.

Click the Ok button.
Now Go to the Extras -> Ad_hoc functions -> Enable the Adhoc Agent Assignment.
Now the enable the Adhoc Agent Assignment Wizard will be opened.

Click the Continue Button.
Now it shows your Task Number and Name and check whether the "insert the workflow constructor and
workflow destructor" will be selected or not. If not means now you select that option.

Click the Continue Button.
Click here to continue...

Ad Hoc agent assignment in Workflow
....Previous

Now the wizard was completed click the Complete Button.
You check the task it will automatically filled the agent name as: &Agent_0001.Agents&
Now you can Save the Workflow and activate it.
Execute the Workflow.
Now its looks like the following figure.

You click the Ad_hoc Agent tab.

You enter the name of the user who wants to do this task . In my Example I entered Developer2. And
then click the Check Agent Button. It automatically creates the random key for that user and it will be
assigned to the Agent_001.

Now again click the execute Button.
Now the Leave Form will be waiting for the user to fill.


Triggering workflow to send an email whenever a material is created
By Chandrasekhar V, EDS
This example focuses on triggering a workflow whenever a material is created using MM01.
TCode SWDD(Workflow builder) -> Click on Create button

Drag and drop the User decision step. Enter the following details

Select the agents Workflow initiator (expression) and click on Transfer and to graphic (tick mark
button).
Following screen appears.

Drag and drop Activity step into branch YES,
Create new task click on the Display task -> Create task


Enter the work item text in the same screen as follows:

To get &_WI_OBJECT_ID.MATERIAL& in above screen, click insert variable icon (above that yellow
icon).
Save in local package.
Go to Additional data menu Agent assignments -> Maintain.

Select it and click on Attributes from application toolbar and select General task radio button, click
Transfer

Click on back 2 times.

Click here to continue...
Triggering workflow to send an email whenever a material is created
....Previous
Click on continue.

Select Workflow initiator as Agents and click on Transfer and to graphic button

To create the workflow container

Select workflow container and double click on BUS1001006 in the list displayed.

Click on properties tab and select the import check box and click on ok

Again open user decision, which was already created, and make changes as bellow
In Parameter1 click F4 and select Material number as bellow

Click on transfer and to graphic
Right click on branch No to send a mail


Click here to continue...
Triggering workflow to send an email whenever a material is created
....Previous
Double click on send mail.
Enter the following details as in the below screen

Click on Transfer and to graphic

Save in a local package
Click on the Basic data(ctrl+F8) from application toolbar and select Start events tab

Enter the details as in bellow screen

Click on Binding

Click on ok
Save and come back to graphic, the following screen will appear

Save, activate and execute.

Go to TCode MM01 to create the material
Enter the details in MM01 and click on Select view -> Basic data1
Enter the details in Second screen as below:

Save and come back.
Check your inbox by using TCode
SBWP.
Double click on Work item executable


Defining Custom Rules for use in SAP Workflow
By Raghava Vakada, Mouri Tech Solutions
I would like to explain about creating custom rules in SAP Workflow. The rules can be created or
changed using the standard SAP transaction PFAC. Once the rules are created you can call these rules
in any workflow via the rule container.

In this article I am creating a rule, which will find the users based on Position id. I have created a custom
function module ZWF_FIND_USERS which will return me back a position under Asset Analyst
(HRP1001-SOBID). The custom function created should have the same interface as that of the SAP
standard function module RH_GET_ACTORS. The following table parameters have to exist in the custom
function module.
ACTOR_TAB STRUCTURE SWHACTOR
AC_CONTAINER STRUCTURE SWCONT
Following is the function module code:
FUNCTION ZWF_FIND_USERS.
*"-----------------------------------------------------------
*"*"Local Interface:
*" TABLES
*" ACTOR_TAB STRUCTURE SWHACTOR
*" AC_CONTAINER STRUCTURE SWCONT
*" EXCEPTIONS
*" NOAGENT_FOUND
*"-----------------------------------------------------------
INCLUDE <CNTN01>.
DATA : POSITION_ID LIKE ZBUSAREA-OBJID,
LT_HOLDERS TYPE STANDARD TABLE OF SWHACTOR,
LWA_HOLDERS TYPE SWHACTOR,
LWA_USERS TYPE STANDARD TABLE OF HRP1001,
WA_USERS TYPE HRP1001,
NUM_LINES TYPE I.
*Read values assigned to the rule criteria
SWC_GET_ELEMENT AC_CONTAINER 'POSITION_ID' POSITION_ID.
SELECT * FROM HRP1001 INTO table LWA_USERS
WHERE OBJID = POSITION_ID.
IF NOT LWA_USERS IS INITIAL.
REFRESH LT_HOLDERS[].
loop at LWA_USERS into WA_USERS.
Condense WA_USERS-SOBID.
LWA_HOLDERS-OTYPE = 'US'.
LWA_HOLDERS-OBJID = WA_USERS-SOBID.
APPEND LWA_HOLDERS TO LT_HOLDERS.
APPEND LINES OF LT_HOLDERS TO ACTOR_TAB.
endloop.
ENDIF.
DESCRIBE TABLE ACTOR_TAB LINES NUM_LINES.
IF NUM_LINES IS INITIAL.
RAISE NOAGENT_FOUND.
ENDIF.
ENDFUNCTION.
Creating a rule using the PFAC Transaction

Assign the function module ZWF_FIND_USERS in the "Rule Definition Tab"

Go to the "Container Tab" and create a container element for the Position id which will be passed to the
function module

Our rule is created now. You can test the rule within the PFAC transaction by clicking the "Simulation"
button on the application toolbar. Now this rule is ready to be used in any workflow according to your
requirement via the rule container of the workflow.

Enter the Position Id, which is created in (PPOCW)

It displays Asset Analysts (users) in the Rule resolution result

Now you can use this rule in any of your workflow definitions.

Maintaining Translations for Work item texts and Outcome names
In this tutorial, we would look into a simple method of translating Work item texts and step names to the
desired language.
Let us open any existing workflow definition.

Check the same workflow definition by logging in German Language:

You can observe that the text remains in the English language, whereas Workflow Started is translated
as Workflow gestartet (As the SAP has already provided translation for this)
Now to translate the text to German, Click on Extras -> Translation -> Translation (As shown in the
screenshot below):

Following pop-up appears: Select German from the list box.

Now a screen with all the workflow steps and outcome names are displayed for maintaining the
translation.

For our testing purposes, let us maintain the German text for the first two step types.

Save and activate.
Now logon in German Language and check the workflow definition. You can observe that for the two step
types, the text is available in German.


Raising exceptions in a method and handling the same in the
workflow
By Suresh Kumar Parvathaneni
This document details the procedure in defining exceptions in a method and using the same in a
workflow.
Let us first look at raising exceptions in a method:
Go to Business Object Builder (Transaction SWO1).
Create a business object.

Now create a method.

Now select the method you have created and click on button Exceptions available on the toolbar.
Following screen appears:

Now click on Create. Following popup screen appears:

Enter the information as shown above. The error type Temporary error is chosen in the case wherein
the record is locked by somebody else or some required resource is not available. The error type
Application Error is to be chosen when there is no authorization for the document you are processing.
The error type System error is to be chosen if there are no values passed for the mandatory
parameters.
Click on continue.

Go back to the main screen.
Now in the method, provide the following code:

Save the business object and release the same.

Try executing the method by clicking on Test/Execute (F8). The exception would be raised as shown
below:

Capturing the exception raised by the method in the workflow:
Go to Workflow Builder (TCode: SWO1).
Create the step Activity

Create a task and provide the following details in the new task:

Save your entries and return to the previous screen.

Click on Outcomes tab. Here you can observe the exception you defined in your method:

As observed in the observe screen, the outcome is not active by default. If we do not handle the
exception, the work item might go into the error status. Activate the outcome:

Save your entries and go back to the main screen of Workflow builder. Please ensure that you have done
the agent assignment for this task.

You can now observe a new branch when the exception is raised. You can define your steps whenever
the exception is raised.
References:
http://help.sap.com/saphelp_nw04s/helpdata/en/c5/e4ad98453d11d189430000e829fbbd/frameset.ht
m

ALE - Error handling through workflow
By Abhijit Daptary & Siddharth Samal, Capgemini India
Pre-requisites.
It is assumed that the reader of this article has some knowledge in SAP workflow BOR objects and ALE
Idoc process like process code, Partner Profile etc.
Description
Here, we will be discussing in details the Error handling of an Inbound Idoc through triggering an event,
which in turn will be triggering a workflow attached to the workflow.
Steps:-
1. Create custom BOR object with the events, Start and Stop event
2. Create a workflow for the error handling, like generating a notification whenever an error occurred
in the Inbound Idoc.
3. Creation of Function Module and attachment with the Process Code
4. Create the settings for the Inbound Process of the Idoc through the Process Code.
Creation of BOR objects. Go to the transaction SWO1.

Enter a name for the Object type and click CREATE button for creating the custom BOR object.

Enter the details required for creating the BOR objects...

Create the Key fields and events of the BOR object.
For creating the Key fields place the cursor on the Key fields and Click on the Create Button

Create events for triggering the workflow and stopping the workflow.
For creating the event place the cursor on the EVENTS and Click the create button like Key fields.
Create two events.
Enter the event name description etc and proceed further to create it.

Similarly create another event for ending the Workflow in the similar manner like that created earlier.

Now, Generate the BOR object through the generate button

Release the EVENTS and subsequently release the BOR object.

After the creation of BOR object
Create a workflow for the generation of notification whenever an error is reached in the Inbound Idoc.
Execute the transaction SWDD.

Click on the CREATE button for creating the workflow for error
handling.
Choose the Step type to be inserted for the notification like here we are using Send Mail option for
sending a mail to the user whenever any error occurred.
To continue, click here

ALE - Error handling through workflow
...Previous
Activate the Workflow and test it whether it is working as per the requirement.
After the successful completion it is required to attach the workflow with the event.
Go to the Header section (Denoted by CAP).

Go to the Start Events
TAB.

Enter the details of the event with which the workflow should be linked like the category, BOR object type
and the event with which that should be linked.
Enter here the BOR object that has been created and give the name of event created for starting the
workflow.
Click on the Binding Button for generating the binding between the event and the workflow.

Generate the binding and click OK button to save the binding.

Click on Activate / deactivate button for activating the linkage.

After the successful linkage the following sign will appear on the workflow.....

This shows that the workflow has been linked to the event and it will be triggered whenever that particular
event will be triggered.
After the creation and successful linkage of workflow with the event it is required it is required to generate
a function module and attached it to the process code.
Go to SE37 transaction and copy a standard process code function module to a custom one. Do no
delete any parameters from the function module as the SAP standard program itself is calling this.
In that function module do the required validation and whenever the validation fails set a standard
parameter WORKFLOW_RESULT to 9999 from within the function module, otherwise normally proceed
to set the status to 53.

After the creation of function module it is required to attach it to the process code and corresponding
attached to the message type at the Partner Profile stage.
To continue, click here

ALE - Error handling through workflow
...Previous
The process code is being created through the transaction WE42
Go to the change mode and click the New Entries button for creating new process code.

Enter the Process Code Name, description and choose the processing type as Processing by function
module. Click on the extension button of Identification.

The details for the of the Process Code after clicking the identification button will be

Whenever idoc arrives into the Destination system then the standard SAP triggers the Process code
attached to the Message type in the partner profile. The partner profile is being maintained in the
transaction WE20.

Since, it is and inbound scenario so the message type and the corresponding process code will be
maintained for the Inbound Parameters.
Click on Create Inbound Parameters button for creating new Inbound Message type and the
corresponding message type.

Enter the process code for the corresponding message type.

Click SAVE button for saving the changes.
Whenever the IDOC arrives into the target system, it checks the partner profile and finds the
corresponding process code. The process code is being linked with the function module through which
the IDOC is required to be

ABAP Classes in Workflow
By Anwesha Bhattacharya , Capgemini India
1. ABAP Classes and Business Workflow:
We can use ABAP classes in the definition and runtime components of SAP WebFlow Engine in the
same way as object types defined in the Business object Repository (BOR).
Before proceeding further we need to know where to create and maintain ABAP Classes and ABAP
Interfaces.
2. What is Class Builder and its purpose?
The Class Builder allows us to create and maintain global ABAP classes and interfaces. Both of
theseobject types, like global data types, are defined in the ABAP Repository, thus composing a central
class library. Together, they form a central class library and are visible throughout the system. We can
display existing classes and interfaces in the class library using the Class Browser.
We can define local classes as well as global classes. They are defined locally in programs, function
groups or as auxiliary classes of global classes of the class pools. Local classes are only visible within the
defining module.

ABAP classes are processed using the Class Builder.

3. How to reach Class Builder?
To reach the initial screen of the Class Builder, choose Development Class Builder from the initial
screen of the ABAP Workbench or enter transaction code SE24.

4. How does it integrate?
The Class Builder allows us to create Web development objects within the ABAP Workbench. We can
use the Class Browser to display and maintain existing global object types from the class library.
The diagram below illustrates the architecture of the Class Builder and the relationships between its
components (including the Class Browser)

From here, we can either display the contents of the class library or edit a class using the Class
Editor.Once we have defined an object type, we can implement its methods. From the initial screen or the
Class Editor, we can also access the Class Builders test environment. We can define the object types
immediately after implementing the method in the ABAP Editor. It is also possible to access the test
environment from the initial screen or Class Editor.
5. How to use the Class Builder?
Use the Class Builder to:
Display an overview (in the Class Browser) of global object types and their
relationships.
Maintain existing global classes or interfaces.
Create new global classes and interfaces.
Implement inheritance between global classes.
Create compound interfaces.
Create and specify the attributes, methods, and events of global classes and
interfaces.
Define internal types in classes.
Implement methods.
Redefine methods.
Maintain local auxiliary classes.
Test classes or interfaces in a simulated runtime environment.
6. What are the constraints?
We cannot define object types on the basis of graphical object modeling.
7. Note before creating global classes and interfaces:
Global classes and interfaces that we create in the Class Builder are stored in the class library and
administered by the R/3 Repository: they therefore have the same namespace as all other Repository
objects. It is therefore necessary to have naming conventions for object types and their components and
to use them uniformly within program development.
8. Naming Conventions in ABAP Objects:
The following naming convention has been conceived for use within the SAP namespace. If we do not
observe the naming conventions for object types (classes and interfaces), conflicts will occur when the
system creates persistent classes, since it will be unable to generate the necessary co-classes.
9. Conventions for Object Types:
Class in the class library CL_<class name>

Interfaces in the class library IF_<interface name>

Local classes in programs
(recommendation)
LCL_<class name>

Local interfaces in programs
(recommendation)
LIF_<interface name>

10. Conventions for Components:
Method name <method name>

Events <event name>

Local type definitions within a
class
(recommendation)
TY_<type name>

Data definitions (variables) <variable name>

Data definitions (constants)
(recommendation)
CO_<constant name>

To Continue....Click here

ABAP Classes in Workflow
...Previous
11. Local Conventions within Methods:
For parameters:
IMPORTING parameters IM_<parameter name>
EXPORTING parameters EX_<parameter name>
CHANGING parameters CH_<parameter name>
RESULT RE_<result>
12. Using ABAP Classes in Workflow:
Within the SAP WebFlow Engine we can use ABAP classes that support the IF_WORKFLOWinterface.
Classes that have implemented the IF_WORKFLOW interface are recognized as workflow-enabled in the
Class Builder.
13. How to create ABAP Classes that support IF_WORKFLOW interface?
Go to transaction SE24 and create a customized class.

Next the pop up appears where we need to mention the detail as follows:

Save it and the class is created.
Now the class is to implement IF_WORKFLOW interface. For this go to the tab and
declare the IF_WORKFLOW as the interface there and press Enter; two sub-interfaces
appear: BI_OBJECT and BI_PERSISTENT. Save the Class.

The ZCL_TEST class now contains the existing methods of IF_WORKFLOW
interface.

14. Lights on Key Attributes and Attributes:
The key attributes are used to define the object key. There can also be other defined attributes other than
key attributes. The SAP WebFlow Engine can access all public attributes of a class.
Key Attributes:
In the Class Builder there is an additional column Key Attributes on the tab page as shown
below:

We need to check this box when we are defining any attribute as the Key Attribute.
All key fields must be character-type fields (elementary types: CHAR, NUMC) and have a defined length.
The maximum length allowed for all key fields is 32 characters. The length of the key field for the
persistent display is 32 characters.
In the case of persistent ABAP objects we can use the GUID, which is generated automatically by the
object manager when an instance is created.
Attributes:
In addition to all the other data types that the Class Builder supports, we can also define attributes with
reference to an object from the Business Object Repository (BOR). To do this, we have to use the
structure SWOTOBJID as the data type. The BOR object is determined using the corresponding value.
To assign a BOR object instance to an attribute we need to use the corresponding BOR macros.
Normally, this is implemented within the CONSTRUCTOR of a class.
To use the BOR macros in a class, two INCLUDES must be included.
Include <CNTN03>contains the local types
Include <CNTN02>contains the BOR macros
An example to show how to define Attributes and Key
Attributes:

To Continue....Click here

ABAP Classes in Workflow
...Previous
15. Why IF_WORKFLOW Interface?
The IF_WORKFLOW interface is necessary when using an ABAP class within the SAP WebFlow Engine.
The interface contains methods that allow the object to be used within the SAP WebFlow Engine.
The SAP WebFlow Engine handles all objects generically. Objects have to be saved in the event of a
context change. Therefore, it is necessary to convert object references in such a way that they can be
saved persistently. Conversely, we have to be able to generate the corresponding instance of an ABAP
class from the persistently saved key.
There are also a number of SAP WebFlow Engine components, for example, the Workflow Log that can
display objects. In this case the object has to provide corresponding functions.
The IF_WORKFLOW interface puts a logical parenthesis round the BI_PERSISTENT (instance
management) and BI_OBJECT (object behavior) interfaces. The IF_WORKFLOW interface contains
the following methods:
BI_PERSISTENT~FIND_BY_LPOR
BI_PERSISTENT~LPOR
BI_PERSISTENT~REFRESH
BI_OBJECT~DEFAULT_ATTRIBUTE_VALUE
BI_OBJECT~EXECUTE_DEFAULT_METHOD
BI_OBJECT~RELEASE
A class that implements the IF_WORKFLOW interface can be used in any workflow. The class
is automatically released for use in workflows when the interface is implemented. Therefore, we
can only make compatible changes to a class after implementation (we cannot delete attributes,
change types or delete methods). There is no where-used list to show which workflows the class
is used in.
Internal classes of an application should not implement the IF_WORKFLOW interface, since
this could mean that each method of the class is used in the workflow. Therefore, we should
encapsulate the workflow functions in another class that calls the selected methods of the internal
class.
Each method of the IF_WORKFLOW Interface as mentioned earlier has its distinct
functionality, which is discussed below.
16. BI_PERSISTENT~FIND_BY_LPOR Method:
If we want to convert a persistent saved display of an object into an instance of the corresponding ABAP
class, SAP Webflow Engine calls the BI_PERSISTENT~FIND_BY_LPOR method.
Features:
The method parameter LPOR is the persistent object reference and is of SIBFLPOR structure type. A
reference of BI_PERSISTENT type is returned.

The following table shows the components of the SIBFLPOR structure:

Field Description
CATID Describes the object type ( CL for ABAP classes)
TYPEID ABAP class name
INSTID Object key. The key is limited to 32 characters.

We can implement this method in several ways. In the case of persistent classes we can create the ABAP
object instance using the generated classes. In the case of individual persistence management we have
to implement the individual actions (such as creating an instance, performing an existence check,
entering public attributes, and so on) manually within the class.

Instance management takes place automatically in the case of persistent classes. In the case of
individual persistence management we also have to carry out instance management by class. The SAP
WebFlow Engine does not provide any instance management. We must therefore implement our own
instance management in the case of individual persistence management.

The FIND_BY_LPOR method should always return the same instance if the following problems are to be
avoided:
Inconsistency in the data display
Instance data being overwritten by another instance
Locking conflicts
There is an implementation example in the CL_SWF_FORMABSENC demo class.

17. BI_PERSISTENT~LPOR Method:
The BI_PERSISTENT~LPOR method is the counterpart to
the BI_PERSISTENT~FIND_BY_LPORmethod. It provides the persistent display for an existing instance
of an ABAP object.
Features:
The method returns the persistent display of an object reference as a SIBFLPOR type structure as
described earlier.
There is a close relationship between the BI_PERSISTENT~FIND_BY_LPOR method and
theBI_PERSISTENT~LPOR method. If we call the BI_PERSISTENT~FIND_BY_LPOR method first and
then the BI_PERSISTENT~LPOR method, the BI_PERSISTENT~LPOR method must return the same
value as was previously used to call the BI_PERSISTENT~FIND_BY_LPOR method.
There are also several ways of implementing this method in this case. There is an implementation
example in the CL_SWF_FORMABSENC demo class.

18. BI_PERSISTENT~REFRESH Method:
SAP WebFlow Engine calls the BI_PERSISTENT~REFRESH method when the system has to ensure
that all values of an object are valid or that they agree exactly with the persistent display of the object.
Features:
The method implementation depends on the internal organization of the class. We can check the object
instance data in the database, if necessary.
If we do not need the method in our class, then we need only to carry out a dummy implementation
(without further coding) to avoid program errors when the system calls the method.
There is an implementation example in the CL_SWF_FORMABSENC demo class.

To Continue....Click here

ABAP Classes in Workflow
...Previous
19. BI_OBJECT~DEFAULT_ATTRIBUTE_VALUE Method:
The BI_OBJECT~DEFAULT_ATTRIBUTE_VALUE method returns the display name of the object.
Features:
We can display references to process objects or process step objects at different positions within the SAP
WebFlow Engine (for example, in Business Workplace and in Workflow Log). The object key is normally
displayed here. If, for example, we want to display a descriptive text instead, the
BI_OBJECT~DEFAULT_ATTRIBUTE_VALUE method has to return the corresponding value.
If the method does not contain implementation or does not return a value, the object key is displayed.
If we do not need the method in our class, then we need only to carry out a dummy implementation
(without further coding) to avoid program errors when the system calls the method.
There is an implementation example in the CL_SWF_FORMABSENC demo class.

20. BI_OBJECT~EXECUTE_DEFAULT_METHOD Method:
The BI_OBJECT~EXECUTE_DEFAULT_METHOD method is the standard method for the object. This
method is executed when, for example, we call the object in Business Workplace.
Features:
We can display process objects or process step objects at different positions within the SAP WebFlow
Engine (for example, in Business Workplace and in Workflow Log). The SAP WebFlow Engine calls the
BI_OBJECT~EXECUTE_DEFAULT_METHOD method.
If we do not need the method in our class, then we need only to carry out a dummy implementation
(without further coding) to avoid program errors when the system calls the method.
There is an implementation example in the CL_SWF_FORMABSENC demo class.

21. BI_OBJECT~RELEASE Method:
The system indicates that the reference to the instance is no longer needed by using
theBI_OBJECT~RELEASE method. This means we can delete the reference from instance management.
Once the last reference has been deleted from instance management, theGARBAGE COLLECTOR can
release the corresponding memory area.
Features:
If we do not need the method in our class, then we need only to carry out a dummy implementation
(without further coding) to avoid program errors when the system calls the method.
There is an implementation example in the CL_SWF_FORMABSENC demo class.

22. How to use ABAP Classes in Process Steps of Business Workflow?
In process steps we can use methods and attributes of ABAP classes in the same way as methods and
attributes of Business Object Repository (BOR) objects. We can call these methods in the process
context.
Features:
While using the ABAP Classes in the Process Steps the methods may contain dialogs, they can be
synchronous or asynchronous; they may appear in the workflow log, and so on.
In general, we can use any method that is implemented as a public method. The method can be
implemented in the class itself, in one of the super classes of the class, or by way of an interface.
The maximum permitted length for methods that are implemented by way of an interface, for
example IF_WORKFLOW~FIND_BY_LPOR, is 30 characters. If the method name is too long, we can
choose a shorter name for the method by defining an alias. If the method is implemented in the class or in
a super class, the name of the method cannot be longer than 30 characters, so this limitation does not
apply.
Parameters:
We can assign values from the workflow container to the method parameters. Conversely, export
parameters can be entered as workflow container values. The following overview shows how the
individual types can be used as parameters:
Simple types (string, integer, and so on)
Data Dictionary types (structures, tables, complex types)
References to objects from the Business Object Repository
References to ABAP classes (supporting the IF_WORKFLOW interface)
We can transfer method parameters that represent a persistent object (IF_WORKFLOW orBOR Object) in
the following ways:
ABAP classes (with IF_WORKFLOW interface)
TYPE SIBFLPORB
Object is transferred using the persistent display
TYPE REF TO <Class name>
Object is transferred as object reference
BOR objects
TYPE SIBFLPORB
Object is transferred using the persistent display
TYPE SWOTOBJID
Object is transferred using the persistent display; this display is only valid for BOR objects
TYPE SWC_OBJECT
Object is transferred as object reference
Exceptions:
The SAP WebFlow Engine can deal with exceptions that are triggered by the methods. It differentiates
between application exceptions and temporary exceptions. The two exception categories are
differentiated by the exception in the class hierarchy or by naming conventions. In the case of a
temporary exception, the SAP WebFlow Engine attempts to execute the method again. In the case of a
permanent error the status for the workflow is set to error.
Class-Based Exceptions:
To create a temporary exception, we can use, for example, the CX_BO_TEMPORARY class or a
corresponding subclass. It can be helpful to trigger an exception for dialog methods when the user
cancels the dialog. Here, for example, we could trigger the CX_BO_ACTION_CANCELEDexception
(subclass of the CX_BO_TEMPORARY class).
Exceptions Not Based on Class:
We can also trigger exceptions not based on class. The SAP WebFlow Engine can differentiate between
the two exception categories (temporary and permanent) by the name. If the exception begins with TMP
or TEMP, it is a temporary exception; otherwise it is a permanent exception.

Using Document Template in Workflow
By Madhavi
This tutorial details about the usage of the step Document from Template in workflow.
Sometimes, it becomes a necessity to work with the documents (Word, Presentation, excel and
others). Go to Transaction SWDD and create a new workflow definition.
Before we go ahead and create a document template, we need to save the workflow definition. Save your
workflow definition.
Now select Document templates from the list as shown below (You can find this on the left side bottom
of the screen)

Click on Double-click to create

Click on Change document class and then select Document from the list provided (see the screenshot
below):

The following screen appears:

Enter some text in the document:

Save your document.

After saving, go back to the main screen. You can observe the document template you just created, as
shown below:

Now in your workflow definition, create a new step Document from Template:

Enter the step name.

To continue...click here

Using Document Template in Workflow
...Previous
In the section, Doc. Template(s), select the document we created earlier using the F4 help. Also enter the
agent details.

Save your entries.
The workflow definition would look like this:

Activate your workflow and execute the same.
Your work item would look as follows:

Execute the work item. The document would open as shown below:

Modify the document and Save.

Your work item is executed.

Demo on using Workflow Wizard
By Nihar Ranjan Barik & Sunil Ojha, Capgemini
Workflow wizards are one of the very strong tools available in workflow builder.
Dialog-oriented user guide that simplifies the definition of workflows in standard situations.
There are wizards that just create step sequences within a workflow definition. These can be found in the
Workflow Builder.
Wizards that create a new workflow definition are located in the Workflow Wizard Explorer. You can,
however, also use these wizards in existing workflow definitions. In this case, a new workflow definition is
not created.
For example I want to attach a report in a workflow, workflow wizards will make this very easy and
effective.
Step1. Go for the transaction SWDD (Workflow Builder)
Click on Step type that can Be inserted and the select Workflow Wizard (see the screenshot
below)
After that Double Click On Include "Exclude Report" from Others tab


There will be two options for executing the report in Dialog/ Background Processing.

Give the Repot name, which is going to be executed. Here the report Name is ZWORKFLOWTEST.

Enter the select option name for the Selection screen of the report.

Here we are selecting For the report execution with the selection screen.

Enter the work Item text.

Continued...

Demo on using Workflow Wizard
....Previous
Edit the basic data of the task that the new step references.

With this we are into the last step of this process. Press the complete step from the screen.


In the further step agent assignment is done

In the general Task we are selecting for General task.

Now it is the time to test our work Flow


In Result to the work flow execution the following screen of the report program will result

The simple output for this testing workflow is shown.


Steps to transport the Agent assignment from one system to another
By Vijayendra Krishnamurthy Rao, Hewlett-Packard
Problem Statement:
I have developed a workflow that I want to transport to a production client. After much testing I changed
the agent assignment to general task and then transported to QA but the agent assignment did not
actually got transported.
How do I get my agent assignment into a transport so that I can move the agent assignment from one
system to another system?
Solution:
Step 1: Go to transaction RE_RHMOVE30

Step 2:
Select Plan version: 01
Select Object Type: TS
Select Object ID : your 8 digit task id number e.g. 99999999
Also,
In the Transport section enter or create your change request
Select "Transport Objects" and
Deselect "Test" and "With Lock"

Step 3: Execute and go to next screen.

Step 4:
On the next screen select the row with your task id Press "Add to Transport"
Then again select the row with your task id and press "Transport/Delete" this will bring up the prompt to
create a customizing request as shown below.
Remember: After clicking on Add to Transport you need to further click on Transport/Delete without
doing this together you wont see anything happening on your screen.

Step 5: Create the transport request to add the agent assignment in the transport by clicking on the
create button.



Step 6: Go to SE09 and release the transport and you now transport your change request as normal.


Defining Custom Rules using responsibilities in SAP Workflow
By Geethanjali K, Kaavian Systems
In this tutorial, we would discuss about creating custom rules using responsibilities in SAP Workflow. The
rules can be created or changed using the standard SAP transaction PFAC. Once the rules are created
you can call these rules in any workflow via the rule container.
First go to PFAC transaction and enter the rule name like znew_rule. Click on create icon. It will show you
the screen like as follows:

Give the name of the rule and choose the rule type as agent determination responsibilities.

Now go to the description page and give the rule description. Choose change text.

Go to the container tab and create a container element


And choose the ok button. Now you have added a rule container element for netvalue (ekpo-netwr)
value.
After that go to the responsibilities tab. Here we can provide the agents for this rule.

Enter the abbreviation and press ENTER.

Now, for example, choose the net value as 0 to 1000 and click on save.

The responsibility defined is in RED color. After saving the responsibility it will show the green color
status.

Click here to continue....

Defining Custom Rules using responsibilities in SAP Workflow
...Previous
Now go back to the Responsibilities tab. Choose insert agent assignment (see the screenshot below).


Choose your desired object type and choose create button. Now agent is assigned for your netvalue
between 0-1000.

You can assign several users for different netvalues. Lets assign one more agent when the netvalue is
between 1001-2000.

And you have to insert the agent for this net value range.

Try simulation run for this


Enter the netvalue as 1000 it will show you the agent for this value.

Now you can use this rule in your workflow. Do not forget to do the binding between workflow container
and Rule container for the container element netvalue.

Using Start Conditions in Workflow
By Geethanjali K, Kaavian Systems
Go to transaction SWDD and create a new workflow definition. Then choose basic
data.
Give the abbreviation and choose save. After that chose the tab start events.
Enter the following values:
Category: BO (Business Object)
Object type: BUS2032
Event: Created
Activate the event linkage and choose the binding button. Following screen appears:

In the above screen, A denotes Event linkage, B denotes Binding and C for Start Conditions
Click on Conditions button. Chose sales organization from the pop up screen as shown below.

And choose the operator as (=) equal to and choose the constant as 3000.

Now the workflow would only execute when the sales organization is 3000.

Using Check Function Module in SAP Workflow
By Geethanjali K, Kaavian Systems
Following is a custom function module created for our demo purpose, which will check the conditions
before triggering the workflow.
FUNCTION ZGEE_SALES_ORG.
*"----------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(OBJTYPE) TYPE SWETYPECOU-OBJTYPE
*" VALUE(OBJKEY) TYPE SWEINSTCOU-OBJKEY
*" VALUE(EVENT) TYPE SWETYPECOU-EVENT
*" VALUE(RECTYPE) TYPE SWETYPECOU-RECTYPE
*" EXPORTING
*" REFERENCE(RESULT) TYPE C
*" TABLES
*" EVENT_CONTAINER STRUCTURE SWCONT
*" EXCEPTIONS
*" NOT_TRIGGERED
*"----------------------------------------------------------------
TABLES: VBAK.
DATA VKORG LIKE VBAK-VKORG.
SELECT SINGLE VKORG INTO VKORG
FROM VBAK WHERE VBELN = OBJKEY.
IF VKORG = '3000'.
RAISE NOT_TRIGGERED.
ENDIF.
ENDFUNCTION.
Now go to transaction SWE2 and insert your object type, event, and the receiver type.

Double click on your entry, following screen appears:

Provide the name of the customized function module name created earlier in the check function module
field.

Now workflow is triggered only when the sales order is created with the sales organization 3000.

Retrieving the Work item information for the deleted users
By Arghadip Kar, IBM India
The request can be that a particular User has been deleted from the SAP system as he is no more in the
company and we need to retrieve the work item Ids that are present in the inbox.
First approach check whether the user Id exist in system using SU01D.


The corresponding User-id does not exist in the system.
We generally used to ask the Security Team to activate the user Id to retrieve the workitem id, which is a
long process and may be misleading to other users, as the user will be activated for sometime.
Now go to transaction SE16 and enter the table name as SWWORGTASK. Here you need to give the
User Id along with the Object Type (US) in the field ORG_OBJ as shown in the screenshot.


Now as a monitoring tool we can also use transaction Code SWI2_ADM2 which retrieves the work item id
assigned to deleted users.


Now by picking up the entire work item Ids we can either re-execute the rule for the work item provided
some rule is used as the agent assignment step or in the task level shown in the screenshots.


We can also use the work item Ids that are retrieved from SWI2_ADM2 transaction to track the users that
are deleted and inform the concerned set of users. May be the user Id of a person has changed so we
need to retrieve the work item id that was present in the previous user id to be forwarded to the new users
id.



Transporting Organizational Structure from one system to another
By Ribhu Ahuja, Tata Consultancy Services
Scenario:
We have two systems DEV (Development) and QA (Quality) These are CRM 2007 systems or they
can be SAP R/3 systems as well. We have an org structure created on the DEV system and we want to
replicate it in the QA system.
Steps and reports used:
First of all, let us see the organizational structure in the dev server. Use T code PPOMA_CRM to see the
same. In R/3 systems, the TCode would be PPOME.

We need three standard reports to completely transfer the HR data from one system to the other. These
reports are RHMOVE00, RHMOVE30 and RHALTD00.
First, we execute the report RHMOVE00 on the DEV server.

In the Plan version, choose 01 current plan version.
In Sequential file box, in file type choose P for physical file and PRESS ENTER.

In the field File name, press F4 and it shows the directory to choose the file from.

Notice the directory name here - /usr/sap/dev/work - this is the default directory of the dev server on
which we need to create a file (BASIS consultants would be helpful here). Give this directory name to the
basis person and ask him to create a file there named hrdata and grant you the write permission to this
file. We will use this file hrdata to export our records from dev server. This file would be Unix or Windows
NT based file depending on the server type. The basis person will create this file hrdata on the specified
server path. Once the file is created, it will show on the list of file name:

Now choose this file and return to the previous screen.

Now execute the transaction. It shows the list of entries exported:

Now, our file hrdata contains all the data, which needs to be imported to the QA server. With the help of
BASIS consultant, copy the file hrdata from DEV server to QA server i.e. from path /usr/sap/dev/work to
/usr/sap/qua/work with the same rights and permissions provided on the dev server.
Note: If our requirement is to transport the HR data from one client to another, we can do the same by
clicking on button and specifying the client to which we want to transfer the
data.
In the other scenario, where we are copying data from one server to another,
this task wont solve our purpose. In QA server, run the report RHMOVE00
and choose P for physical file. This time, our working directory would be /usr/sap/qua/work/hrdata. Once
you execute the report in the quality server, the following screen appears:

Click here to continue...

Transporting Organizational Structure from one system to another
...Previous
Click on the button. We get the following screen:

Execute the report and we see the following screen:

Press the button and we are on the batch input session screen (SM35)

Choose our entry PD and click on the button. If we choose foreground update, we can
see the data being updated in the screens as shown:


This way all the master data will get uploaded to the quality system. This will transport all the master data,
but if we compare the TCode PPOMA_CRM of DEV and QA servers, it will show that the organizations
have been created, positions beneath them are created but the persons attached to the positions are not
showed up. For doing that, we need to execute the report RHMOVE30 on the dev system and we see the
following screen:

Make the entries as shown in the figure and hit F8. We see the following screen:

Click select all - and then click . It asks for the transport request number:

Give the same or create a new request. Once done, release the request and transport the same. After the
request is transported, execute the transaction PPOMA_CRM in QA server. Thus we see that the entire
org structure is transported to the QA server from the DEV server. Now we see the persons attached to
the positions too.

Configuring events for HR Workflow
By Sri lakshmi Lavanya Koduganti, CSC
Scenario: Suppose you have created a Custom Infotype (Say 9048) and you want to trigger an event
(Say ZRTW_INS event on the Business Object BUS1065) whenever a new record is inserted into this
Infotype.
Step 1: Go to TCode SWEHR1.

Click on New Entries tab
Step 2: Enter the following details

This links the Infotype with the Business Object.
Step 3: Go to TCode SWEHR3. Click on create New entries tab.
Enter the following details.

Here Update op. indicates the operation, which triggers the event
At the bottom, Object type is the Business Object (which is already linked to the infotype 9048 in
SWEHR1) and Event is the event on the Business Object.
Save the entries.
Now we have configured the event ZRTW_INS on the Business Object BUS1065 to trigger whenever a
new record is inserted in IT9048.
We can also mention a Function module here instead of Event. This function module contains the code to
trigger

Trigger Workflow from Messages
By Suresh Kumar Parvathaneni
This document details about the procedure in triggering the workflows from a message (For e.g., error or
warning message).
For our demo purpose, let us consider the transaction ME21 (Create Purchase Order). Without entering
any values on the screen, press ENTER. You would get the error message Enter Purchasing Org. (as
shown below)

Now double-click on the message, to get the long text and the message details.

Now click on the technical information.

The above screenshot provides us with the message details (Message Class: ME) and Message Number
083.
Now we need to create a workflow which needs to be triggered from this message.
Go to transaction SWUY. Following wizard appears.

Click on Continue.

Enter the message details, as obtained earlier. Click on Continue.
Continued...

Trigger Workflow from Messages
...Continued

Click on Complete again. Pop-up screen regarding the package (Development class) appears. Assign
the package, you would like to have. Press ENTER. You would be automatically navigated to the
Workflow Template screen shown below:

Enter the Work item text and click on Workflow Builder. We are now in the Workflow Builder screen.

For our demo purpose, lets create a simple email step in our workflow definition. (To know about how to
include an email step in the Workflow definition, click here)

Activate the Workflow definition.
Testing the application
Go to transaction ME21.
Without entering any values, press ENTER. The error message Enter Purchasing Org. appears. Double-
click on the message and the long text appears. See the screenshot below.

As highlighted in the screenshot above, the button Workflow is now enabled (before attaching a
workflow definition to this message, this button was disabled. Click on the button Workflow. The
workflow definition created earlier, in this case WS99900061, is now triggered. See the screenshot
below.


Triggering Workflow using Business Transaction Events (BTE)
What are Business Transaction Events?
The enhancement technique (Open FI) that were developed for Financial Accounting Component.
Open FI is based upon the following principles:
o Application developers must define their interface in a function module, an assignment table
is read in the accompanying code and the customer modules assigned are called
dynamically.
This can be easily adopted / customized to the business needs wherein SAP does not provide the
standard functionality through customization or enhancements. This functionality is primarily used in
FI in the areas of dunning, credit management, banking etc. For Example: Standard Dunning
functionality in SAP sends the notice to the Pay to partner function (based on the partner functions in
SD module i.e. pay to hits the books in Accounts Receivable in FI module), whereas the requirement
could be to send the same to Bill to party, based on the premise that the original invoice was sent to
him as per the partner functions in SD.
Basic steps in configuring the Business Transaction Events:
Company A would like to fill the Assignment field with custom value Demo BTE when an accounting
document is posted for a certain Company Code for accounting purposes to analyze the data. To
accomplish this requirement, Company A will use the Business Transaction Event 1120, Post Document:
SAP Internal Field Substitution. Depending on the business scenarios, generally the reference document
number field and assignment number field will be populated with a unique identifier for analyzing the
accounting data. For the purpose of this document, I have used a scenario of populating the text field
while creating accounting document.
IMG Menu Path: Financial Accounting ->Financial Accounting Global Settings-> Business
Transaction Events-> Environment-> Infosystem (Processes).

Execute the search with the defaults.

Find the correct interface for updating the document.

Place the cursor on the key 00001120 and click on Sample Function Module
This navigates you to SE37 Function Builder. This is the function module
(SAMPLE_PROCESS_00001120) we would need to copy into a Z or Y function module for coding
Click on copy button.

Specify the function module name and the function group.
Now in the SE37 screen, click on change button and enter the following code:

Save and activate the function module
Go back to the first screen by multiple clicking on BACK.

Click here to continue...

Triggering Workflow using Business Transaction Events (BTE)
....Previous
To assign function module to the event, we need to create a product, say ZPRODUCT. Click as
shown below:

Click on New entries.

Ensure that the Active check box is checked, otherwise BTE wouldnt trigger.
Now we need to assign the function module created earlier to the event
Click as per the following screenshot:

Click on new entries and create the following entry for 00001120:

Test the BTE by creating a document through FB01 transaction.
To check whether the assignment field is filled with Demo BTE, display the created accounting
document from FB03 and check for the Assignment value.


Double click on the item.

Triggering business object events:
Update the Z function module that is created earlier by calling the function module
SWE_EVENT_CREATE to trigger a business object event. Link this event to the workflow. To know
about triggering an event programmatically, click here.
Triggering an event using Function Module Enhancement
By Saumya Govil, Infosys
Issue
For an opportunity, there is an associated OQT (Opportunity Qualification template) IBPO
QUALIFICATION, which has to be sent for approval using SAP workflows.
This OQT is a Java survey application that is embedded inside an opportunity.

The requirement was that whenever an OQT is saved, a workflow should be triggered to send this OQT
for approval. The OQT save button is a Java button that cannot be recognized directly by SAP system.
Software requirements
SAP CRM 2007
Solution
1. Go to transaction CRM_SURVEY_SUITE.
2. Go to Application -> Opportunities -> IBPO Qualification

3. Go to Extras -> Settings


When this survey is saved, it makes a call to CRM_SVY_OPPORT_PAI function module. This is the
linkage of the Java application to SAP.
4. Go to SE37 and open the CRM_SVY_OPPORT_PAI function module.
5. Go to Edit -> Enhancement Operations -> Show Implicit Enhancement Operations.

This would show the implicit enhancement points for the function modules. By default, the implicit
enhancement points are at the start and end of the FM.


Click here to continue....

Triggering an event using Function Module Enhancement
...Previous
6. Click on the Enhance button on the top of the FM.

7. Go to the end of the FM and click on the yellow line. Now go to Edit -> Enhancement Operations ->
Create Enhancement.

8. Now you would get a popup. Select Code.

9. Now enter the details of the new enhancement.

10. A new enhancement would be created ad the following code would be added to the end of the FM.
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""" A
*$*$-Start: (2)--------------------------------------------------------------
----$*$*
ENHANCEMENT 1 Z_IBPO_OQT_EVENTTRIGGER.
*
ENDENHANCEMENT.
*$*$-End: (2)--------------------------------------------------------------
----$*$*
ENDFUNCTION.

11. Now write the code to trigger the event of the business object inside this enhancement. This code
would be executed when ever an OQT is saved.
Call the FM SAP_WAPI_CREATE. This FM accepts the business object name, Opportunity GUID
and business object event name as input and triggers the BO event.
DATA: GUID1 type sweinstcou-objkey,
rcode type SY-SUBRC,
event_id type SWR_STRUCT-EVENT_ID.
GUID1 = lv_object_guid.
CALL FUNCTION 'SAP_WAPI_CREATE_EVENT'
EXPORTING
OBJECT_TYPE = 'ZBO_TEST'
OBJECT_KEY = GUID1
EVENT = 'OQTSaved'
* COMMIT_WORK = 'X'
* EVENT_LANGUAGE = SY-LANGU
* LANGUAGE = SY-LANGU
* USER = SY-UNAME
* IFS_XML_CONTAINER =
IMPORTING
RETURN_CODE = rcode
EVENT_ID = event_id
* TABLES
* INPUT_CONTAINER =
* MESSAGE_LINES =
* MESSAGE_STRUCT =
.
12. Save and activate the enhancement. Go to Function Module -> Activate Enhancement.

13. Save the Function Module.
14. Associate the Z business object ZBO_TEST -> OQTSaved event as a triggering event of a workflow
and do the required processing. (BO creation and event association with the workflow is out of scope
of this document).
15. Execute the Opportunity transaction. On save of the OQT, the function module
CRM_SVY_OPPORT_PAI would get triggered which would in turn trigger the business object event.
This would trigger your workflow!
NOTE: This implementation can be used for save on any survey. Also enhancement of any function
module can be done similarly. This approach might seem simple, but has vast implications so should be
used with care. Also function module enhancement is only possible on SAP CRM 2007; older versions do
not support it.
Conclusion
The issue of triggering a workflow from a Java save button was solved.

Passing a hyperlink in a Work item
By Sourav Roychowdhury, Capgemini India
In this scenario, we will check how a hyperlink is passed in a work item text. It will appear as hyper link.
When we click on the same, it will take you to the corresponding website.
For the same we will prepare a simple Workflow for leave request. The workflow will have a user decision
task step and following that email steps for confirming the approval/rejection of leave request.
In the decision task text, the URL will be passed as hyper link.

After saving the WF, click the Builder button.

As we want to pass different text in the decision task, copy the standard task TS00008267 and create a
new one.
Before that let us create a WF container element to hold the value of URL and pass it to the task level.


Lets us now create the new decision task.


Click here to continue...

Passing a hyperlink in a Work item
...Previous
Let us create a container element here for the hyperlink and then prepare the description. In description,
remove the already existing text.

Here HYEPERLINK is the task container element which contains the URL.
Save the task and go back to the WF and complete the binding.

Activate the WF and it will finally look like this.

Now test the WF. For testing purpose, we will use the URL www.rediff.com. Otherwise one has to
prepare the URL in the method or by any means and pass it in this container.

The WF has started; please check the SAP inbox to check the message.

The URL comes as hyperlink. Let us click on it and check.


Working with Business Objects in SAP
By Swetabh Shukla, Infosys
Business Object type contains methods, attributes and events which give a component based view of any
Business Process.
For example we have a Purchase Order business process. This process includes various small
functionalities. It will have process of changing Purchase orders based upon requirements, functionality to
retrieve the details of purchase order etc. Each of these functionalities is encapsulated inside a method.
The method can call the function modules present in R3 system or can have there own code to execute
some functionality. So if we consider Purchase Order as a Business Object then it will be identified by key
field Purchase Order number. Each purchase order business object based upon key field purchase order
number is different. Its so because each purchase order is different and will contain different details.
So the methods contain business functionality. Attributes are just like properties of the Business
object. For example for any purchase order Purchasing Group, Purchasing Organization etc are
attributes.
Technically we can say that business object types are just like any template. At runtime we instantiate or
create runtime objects for any BO (Business Object) type based upon the key fields we pass. Two
runtime Business objects of same BO type are different from each other based upon the key fields we
pass. So the key field is the differentiating factor for two or more runtime business objects of same BO
type.
To Browse for BO open tcode SWO2 (Path -> Tools ->ABAP Workbench->Overview->Business Object
Browser).

You can expand the nodes and can check various business objects in BOR. You can double click on the
BO node and it will take you to BO display (SWO1).
1 Working with Business Object in our programs
For creating a Business Object and its attributes there are many already existing tutorials. So in this
tutorial we will not discuss creation of BO and its attributes.
1.1 To create instance of a BO
To create an instance of BO we need to have the key fields of that BO. Key fields will be used to uniquely
identify the BO. We can use the FM 'SWO_CREATE' to create an instance of BO in any report program.
DATA:
i_objtype TYPE swo_objtyp,
i_objkey TYPE swo_typeid,
object TYPE swo_objhnd.
i_objtype = <Business Object>
i_objkey = <BO key>
CALL FUNCTION 'SWO_CREATE'
EXPORTING
objtype = i_objtype
objkey = i_objkey
IMPORTING
object = object.
The variable object will hold runtime instance of the object type.
The other way is to use the macros defined in include <cntn01>
INCLUDE <cntn01>.
DATA:
i_objtype TYPE swo_objtyp,
i_objkey TYPE swo_typeid,
object TYPE swc_object.
*Create instance of Object type
swc_create_object object i_objtype i_objkey.
Internally the macro calls the FM SWO_CREATE. So you can either go for direct FM call or the macro
call.
1.2 Container
Basically the term Container is used with reference to Business Objects and Workflows. The Container
actually holds import and export parameters associated with any method of Business Object at runtime.
When ever we are calling any method of Business Object we need to populate container for import
parameters and after the method gets executed it returns the values (export parameters) in Container.
Business Object container is technically of type SWCONT structure.

Here ELEMENT will be name of the variable/internal table which container holds and VALUE will have
corresponding value. For multi line variable or internal tables, the container will hold multiple values with
same element name.
1.2.1 Lets take an example to check what Container is
For example lets create a Business Object ZSWE1 with only one method READ. We will discuss the
creation of BO in very brief.
Key field will be Purchase Order number (EKKO_EBELN) for BO.
Method READ will take Purchase Order number as input and will give all the Purchase Line items in it in
an internal table.
Step 1 : Create BO ZSWE1 for test purpose. You can give it any name.

Step 2 : Now create a method READ

Save the method. Now we will create the parameters of the method.
Import Parameters PurchaseDocument EKKO-EBELN
Export Parameter ITEM EKKO-EBELP (multi line)
PurchasingDocument will be a import parameter of type EKKO_EBELN.
ITEM will be a export parameter of type EKKO_EBELP and will be a multi line variable(internal table )


Click here to continue...

Working with Business Objects in SAP
...Previous
Save the method and then Click on the Program button to implement the method. In the method just
read all ebeln (Purchase line items) corresponding to PO number into internal table ITEM and pass it on
to container in the method. Check the snapshot below.

Check the whole code of the BO program here.
***** Implementation of object type ZSWE1 *****
INCLUDE <OBJECT>.
BEGIN_DATA OBJECT. " Do not change.. DATA is generated
* only private members may be inserted into structure private
DATA:
" begin of private,
" to declare private attributes remove comments and
" insert private attributes here ...
" end of private,
BEGIN OF KEY,
PURCHASINGDOCUMENT LIKE EKKO-EBELN,
END OF KEY.
END_DATA OBJECT. " Do not change.. DATA is generated
BEGIN_METHOD READ CHANGING CONTAINER.
DATA:
PURCHASINGDOCUMENT TYPE EKKO-EBELN,
ITEM TYPE EKPO-EBELP OCCURS 0.
SWC_GET_ELEMENT CONTAINER 'PurchasingDocument' PURCHASINGDOCUMENT.
select ebelp into table item from ekpo
where ebeln = PURCHASINGDOCUMENT.
SWC_SET_TABLE CONTAINER 'Item' ITEM.
END_METHOD.

Step 1 : Save the changes and make the status of the BO to implemented for testing purpose. Also
generate the BO.
Step 2 : Now lets test the BO. For this put a break point in the method READ at the select query. Also
take any PO number which will have multiple line items. You can check EKKO and EKPO tables. In my
case I am taking PO 4200000017. In my R3 system this particular PO contains 4 line items in EKPO
table. Lets put a break point and check the method.

Step 3 : Execute the BO with key 4200000017

Execute the method with import parameter as 420000017

It will take you to debugging mode. Now check the container.
In debug mode before the select statement the CONTAINER will hold only import variable

Now execute the last statement in the method and see the contents of CONTAINER (just before exiting
the method.

So we have seen how the CONTAINER holds values while we are working with Business Objects at
runtime.
1.2.2 Some common macros defined in include <CNTN01> for working with Containers
Functionality Macro
To write a single line variable in Container SWC_SET_ELEMENT
To read a single line variable from Container SWC_GET_ELEMENT
To write a multi line variable or internal table in Container SWC_SET_TABLE
To read a multi line variable or internal table from Container SWC_GET_TABLE
To clear the container SWC_CLEAR_CONTAINER
Further you can check the include <CNTN01> for more macros. Also check the macros. These macros call
some specific function modules that you can use directly in your code.
1.3 Calling a BO Method/Attribute in report programs
We can create a instance of BO method using FM 'SWO_CREATE' or macro SWC_CREATE_OBJECT.
First of all lets consider a BO 'BUS1001006' (StandardMaterial). We will call the method DISPLAY. For
this we will instantiate the BO with key ZSHUKSWE20( material number).
To call a method or attribute of any BO we can use the FM 'SWO_INVOKE'. We have to take care while
we call this FM. Suppose if we want to call an attribute defined in the method, then we need to
populate the import parameter ACCESS with G. If we need to call the method of the BO then we need
to populate the import parameter ACCESS with C.
Lets create a report program and check step by step. We will fetch details of attribute MATERIALTYPE
of BO 'BUS1001006'
*&---------------------------------------------------------------------*
*& Report ZSWET_BO1
*&
*&---------------------------------------------------------------------*
*& To get attributes of BO instance in report
*&
*&---------------------------------------------------------------------*
REPORT zswet_bo1.
PARAMETERS: p_busobj(10) TYPE c DEFAULT 'BUS1001006',
p_key(70) TYPE c DEFAULT 'ZSHUKSWE20' ,
p_attr(32) TYPE c DEFAULT 'MATERIALTYPE',
p_access TYPE c DEFAULT 'G'. "To call method put 'C'
DATA:
i_objtype TYPE swo_objtyp,
i_objkey TYPE swo_typeid,
i_element TYPE swo_verb.
DATA object TYPE swo_objhnd.
DATA verb TYPE swo_verb.
DATA return TYPE swotreturn.
DATA lt_container TYPE STANDARD TABLE OF swcont.
DATA line TYPE swcont.
i_objtype = p_busobj.
i_element = p_attr.
i_objkey = p_key.
* Instantiate the business object. i.e give it a key and create it.
CALL FUNCTION 'SWO_CREATE'
EXPORTING
objtype = i_objtype
objkey = i_objkey
IMPORTING
object = object.
* Return attribute.
CALL FUNCTION 'SWO_INVOKE'
EXPORTING
access = p_access
object = object
verb = i_element
IMPORTING
return = return
verb = verb
TABLES
container = lt_container.
* The attribute value is in the container returned from FM.
IF return-code = 0.
LOOP AT lt_container INTO line.
WRITE: / 'Attribute MATERIAL TYPE is : ',
line-value.
ENDLOOP.
ENDIF.

Lets execute the report and see the output:

Click here to continue...


Working with Business Objects in SAP
...Previous
Now lets see how to call a method of BO. The Method DISPLAY will display the material passed in BO
container.
*&---------------------------------------------------------------*
*& Report ZSWET_BO1
*&
*&---------------------------------------------------------------*
*& To call method with import parameters
*&
*&---------------------------------------------------------------*
REPORT zswet_bo1.
* Get an attribute of a business object.
PARAMETERS: p_busobj(10) TYPE c DEFAULT 'BUS1001006',
p_key(70) TYPE c DEFAULT 'ZSHUKSWE20' ,
p_attr(32) TYPE c DEFAULT 'DISPLAY',
p_access TYPE c DEFAULT 'C'. "To call method put 'C'
DATA:
i_objtype TYPE swo_objtyp,
i_objkey TYPE swo_typeid,
i_element TYPE swo_verb.
DATA object TYPE swo_objhnd.
DATA verb TYPE swo_verb.
DATA return TYPE swotreturn.
DATA lt_container TYPE STANDARD TABLE OF swcont.
i_objtype = p_busobj.
i_element = p_attr.
i_objkey = p_key.
*To call the method we need to populate the Container of the
*BO with importing parameters
CALL FUNCTION 'SWC_ELEMENT_SET'
EXPORTING
element = 'MATERIAL'
field = p_key(18) "Material Number
TABLES
container = lt_container
EXCEPTIONS
OTHERS = 1.
*Instantiate the business object. I.e give it a key and create it.
CALL FUNCTION 'SWO_CREATE'
EXPORTING
objtype = i_objtype
objkey = i_objkey
IMPORTING
object = object.
* To call the Method of the BO.
CALL FUNCTION 'SWO_INVOKE'
EXPORTING
access = p_access
object = object
verb = i_element
IMPORTING
return = return
verb = verb
TABLES
container = lt_container.
The Output will be:-

Lets see an example below on How to Call the methods using the macros defined in include
<CNTN01>.
*&----------------------------------------------------------------*
*& Report ZSWET_BO1
*&
*&----------------------------------------------------------------*
*& Using macros defined in CNTN01 include. To call method of BO
*& For reference check FM DNO_DB_APPENDIX_INSERT
*&----------------------------------------------------------------*
REPORT zswet_bo1.
INCLUDE <cntn01>.
* Get an attribute of a business object.
PARAMETERS: p_busobj(10) TYPE c DEFAULT 'BUS1001006',
p_key(70) TYPE c DEFAULT 'ZSHUKSWE20',
p_attr(32) TYPE c DEFAULT 'DISPLAY',
p_access TYPE c DEFAULT 'C'. "To call method put 'C'
DATA:
i_objtype TYPE swo_objtyp,
i_objkey TYPE swo_typeid,
i_element TYPE swo_verb.
DATA: gv_mat TYPE swc_object.
i_objtype = p_busobj.
i_element = p_attr.
i_objkey = p_key.
*Define container
swc_container container.
*Create instance of Object type
swc_create_object gv_mat i_objtype i_objkey.
**gv_mat will contain instance of the BO
*To clear a continer
swc_clear_container container.
*Now to call a method fill up container with import parameters for method
swc_set_element container 'MATERIAL' p_key(18). "'MATERIAL' ->import
parameter
*For container of type table use swc_set_table.
***If any more import parameter are there for the object then populate them
***also using swc_set_element and swc_set_table
*In this case no more import parameters
*To call a method stored in p_attr
swc_call_method gv_mat p_attr container.
*If there are any export parameter, then CONTAINER will have the values
*and we can read from container
The Output will be:-

1.4 To trigger an Event of BO
We can use the FM SWE_EVENT_CREATE to raise an event in any report program. An explicit commit
work is required after the FM call to trigger the event, other wise event will not be raised.
*&---------------------------------------------------------------*
*& Report ZSWET_BO1
*&
*&---------------------------------------------------------------*
REPORT zswet_bo1.
INCLUDE <cntn01>.
* Get an attribute of a business object.
PARAMETERS: p_busobj(10) TYPE c DEFAULT 'BUS1001006',
p_key(70) TYPE c DEFAULT 'ZSHUKSWE20'.
DATA:
i_objtype TYPE swo_objtyp,
i_objkey TYPE swo_typeid.
i_objtype = p_busobj.
i_objkey = p_key.
*Define container
swc_container container.
*To clear a continer
swc_clear_container container.
*You can populate the Container if required
*To generate event
CALL FUNCTION 'SWE_EVENT_CREATE'
EXPORTING
objtype = i_objtype
objkey = i_objkey
event = 'CREATED'
TABLES
event_container = container
EXCEPTIONS
objtype_not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
" MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
" WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4
" RAISING OBJTYPE_NOT_FOUND.
ENDIF.
COMMIT WORK.

Just triggering an event does not makes any sense until and unless a proper event receiver id is linked to
the event. This event receiver can be a FM or can be any workflow. Event linkage can be done in SWE2
or SWETYPV transactions.

To instantiate any Business object in a Workflow
By Swetabh Shukla, Infosys
1. Go to SWDD and create a new workflow. This workflow will have two steps. This is just for test
purpose so we are not going to define any triggering event etc. First step will instantiate (creating a
runtime object) a business object and second step will use that runtime object to execute one of its
method. We know that to instantiate any BO we need the object key to be passed. Key uniquely
identifies a runtime instance of Business Object (henceforth we will refer it as BO or business object
interchangeably).
Note: BO = Business Object in all the references below.
For example use BO BUS1001006. This BO is for Standard Material. Let us consider a material
number ZSHUKSWE20 in this case. The method DISPLAY of BO can be used to display the material
passed in key field of the BO BUS1001006. We will try to instantiate the BO for object key =
ZSHUKSWE20 which is material number in current scenario.
We will use Business Object SYSTEM and method GENERICINSTANTIATE to instantiate any
Business Object in
workflow.

The workflow template will look like this.

2. Define a container element of Business Object type which you want to instantiate in a workflow.
We will define a container element of type business object BUS1001006.

3. Now Create an Activity type step and use Business Object SYSTEM and method
GENERICINSTANTIATE. This task will be background task since we dont want any interaction
with users.

Create the task from workflow builder directly.

In binding of the task with method pass variables objectkey and objecttype. These will be created
automatically in Task container. The method will return runtime object in export parameter
OBJECTINSTANCE.

Save the task and go back to workflow builder.

Now create binding between TASK and workflow. Now here you can pass hard coded values for
OBJECTKEY = Material Number and OBJECTTYPE =
BUS1001006

Save it and finally we have added a step which instantiates a business object. Lets use this instance to
display the material ZSHUKSWE20. This step will return runtime object of type BUS1001006 and key =
ZSHUKSWE20.
Click here to continue...

To instantiate any Business object in a Workflow
...Previous
4. Create a new activity type step and create a new task for this.

This task will just call method DISPLAY of BO instantiated. The method takes some parameters as
input but for our current scenario even if we dont pass import parameter (non-mandatory) it will not
be a problem. We are just checking runtime existence of Business Object. So we dont have to worry
about the binding between method and task. But in real scenario do create proper bindings to avoid
any error.
Also do not forget to make the task General task so that any one can execute. Also assign Workflow
Initiator as agent so that you can test in workflow builder. In real scenarios take care of agent
assignment.


Now after we have created the task. Go back and then create binding between task and workflow. We
just need to pass our Container element MATERIAL to the task so that the task executes the method
DISPLAY with the key ZSHUKSWE20 and displays the material.

Save the step and activate the workflow.

If we execute the workflow we can check the BO getting instantiated and material getting
displayed.
Directly execute the workflow and check. Go to Business workplace and check. You can see the
work item

Execute the work item and then check

So we can see the material ZSHUKSWE20 getting displayed which proves that the BO BUS1001006
was instantiated in workflow.
This way we have seen how to instantiate a Business Object in our workflows. The same we can replicate
elsewhere and can .

Raising events based on change document (Workflow)
By Kartik Tarla, Infosys
Introduction:
Many business objects are changed frequently. Often we are required to trace the changes made. We do
this by tracking the change documents.
To be able to log changes to a business object in a change document, an appropriate change document
object must be defined in the system. In its definition, a change document object has tables, which
represent a business object in the system. Changes to table fields designated as change document-
relevantare logged by writing a change document.
We assign a change document object to an object type/event pairing and determine the action (create,
change or delete) on the application object for which the event is to be created. We can classify the event
in order to create three different events for a change document i.e. create, change & delete.
The change document is written only when change is updated, this ensures that the event is not created
until the change has actually been made.
The Assignment between a change document and event is maintained through transaction SWEC.
When the particular event is triggered, then we can carry out the further processing by assignment of a
receiver function module and a receiver type to a particular combination of object type and event, this is
done through the transaction SWETYPV.
In the receiver function module we can do the custom coding to achieve the functionality which is needed
whenever the business requirement demands that certain work needs to be done when a change is
made. Our processing may stop at the receiver function module itself or we may proceed to trigger a
workflow.
This procedure can also be considered as an alternate way of achieving functionality that at present is
fulfilled using Exits, BADIs and BTEs.
Suppose the requirement needs certain action to be performed when the changes to any transaction are
saved. The first approach that generally is followed is to look for exits or BADIs, but mostly the problem
faced is, that all tables may not be updated at the point where the exit is being called, or the changes may
be cancelled after the exit call which may then require to take back our actions which we performed inside
the exit. So in such cases a much better and cleaner approach is to make use of events, which trigger on
change document.
This association we do in SWEC, where we assign the business object type, event and the change type
to a change document.
SWEC:

We can also put field restrictions to put conditions on triggering of the event.


Now when the event is triggered, to carry out the further processing we assign a receiver function module
to the event in transaction SWETYPV.
SWETYPV:


The receiver function module must have the interface as this fm SWW_WI_CREATE_VIA_EVENT.
Now we can perform the required action inside the receiver function.
Scenario:
Consider the following scenario where we can use the concept of triggering events based on changes
made to business objects.
Business Requirement:
To trigger a mail to be sent to the Sales Order creator whenever any changes are done to the schedule
lines and the indicator Fixed date and Qty is checked.
Technical Solution:
The change document for sales order related changes is VERKBELEG, and the business object is
BUS2032.
So we create an event SCH_CHANGED and assign it the change document VERKBELEG in
transactionSWEC.
Now assign a receiver fm to the bus/event - BUS2032/SCH_CHANGED in transaction SWETYPV.
Inside this function module we write the code to trigger the mail.

Extended notification configuration
By Mohan Babu K J, IBM India
Goto T-code SWNCONFIG.
Copy the STANDARD Category to ZMAILNOTIF and save as shown below.




Select the Category and choose Assigned Message Templates and choose One Message per
Notification in Granularity and save as shown below.

Double click on Delivery Schedule in Dialog structure and create New Entries as shown below.

Double click on Subscription Basic Data and create New Entries for as shown below. Mention the delivery
schedule which created previously.

Click here to continue...
Extended notification configuration
...Previous
Double Click on Subscription Settings in Dialog Structure and give ATTACH1 in SHOW_INBOX_AS if you
need to open the inbox from the attachment of the mail. If you do not want any attachment to open work
item, leave the values as blank.

Double click on Filter Basic Data and create New Entries for Workflow Scenario as shown below.


Double click on Filter Settings and give X to Delta parameter.

Double click on Schedule Selection and give the filter value and choose in which are all days it should
schedule to send the notification and on what interval.

The below screenshots are as per standard settings and no need to do anything on that.



In SE38 tcode create a variant for program SWN_SELSEN and enable the check-box option No Time
Check During Send and save the variant.
Schedule this program in background job in SM36 with variant for every 15 minutes or what interval
needed.
Before testing, check whether the services provided in below link are active in SICF.

Debugging SAP events
By Saurabh Asthana, Infosys Technologies
Overview:
This document explains how receiver Function module can be used as a Substitute of BAPIs and Exits
in particular cases and how to debug those events, as general debugging method can not be used for
them.
This document is categorized into:
Introduction of events
About receiver FM
How to debug related event
INTRODUCTION OF EVENTS:
Events indicate the occurrence of a status change of a Business objects.
Events always belong to an object and are therefore described as definition components in the
object type
Events can have parameters & exceptions like methods
These events have listeners (outside the BO). E.g., workflow
We can create our own events also.
Procedure to create Events:
a) Position the cursor on the entry Events. And then press create
b) Now enter the following texts for the event to be created
C) Give Event, Name, Short description


Irrespective of whether you use uppercase and lowercase in the event name, the name is always
entered in uppercase letters in the event receiver linkage table by the system.
The event has now been created and is available in the Business Object Repository.
You can now use this event in the other definition tools in SAP Business Workflow.
Position the cursor on the new event and choose Edit Change release status Object
component to implement.
The object type must first be generated so that it can be instantiated and tested.
About Receiver FM:
If we have a requirement like insertion of an entry in a table when material is changed in a sales order
or we want some functionality to happen when a purchase order or sales order is created, generally
in such cases we look for BADIs and exist, these are called after the save events are triggered and
we place our logic there.
But we can also have a separate approach in which we link the event to a function module through
Transaction SWETYPV and the logic are written in the FM to satisfy the requirement.
Now if we want to Debug that code, just by putting the break point there, we cannot reach their directly
So for this purpose below mentioned method should be followed, this procedure is very useful and can
be utilized wherever we want to debug the events.
First go to transaction SWETYPV then new entries.

Here on changed event we have written our logic in (This function module is created by copying
standard receiver FM SWW_WI_CREATE_VIA_EVENT) and put the break-point there and this
ZRECEIVERFM is linked with the event by using transaction SWETYPV.
Here object type Bus2032 is taken which is for sales order, as here we are taking the case where
In a sales order while changing the quantity, the change event is triggered and then we are
linking this event to ZRECEIVERFM where we put our logic.


Now we go to our transaction code VA02(change sales order)


Click here to continue...

Debugging SAP events
...Previous
How to debug the event:
Now we will change the quantity of item, from 916 to 917 then press enter and start debugger(/h) as
shown:

It will come to the following screen there go in setting --> update debugging.

Note: Before switching on the debugger check that the default debugger should be classic debugger
(check in SE38-->utilities-->debugging-->ABAP debugger)
Now press execute, then it will come to following screen, there go in setting --> Breakpoint at --> Method.
A pop-up will appear, in that give the class name as CL_SWF_EVT_STRATEGY_BOR_FB and
in Method giveprocess.

Now press execute.


Now from here press F5, then after coming to CASE me->process_mode, here change the mode
manually as D (for debugging) as shown below.

Then execute, then we come to the our own created ZRECEIVERFM, where break point is set and
Logic is written.

Thus we can analyze and debug the logic.

Sending workflow notification to Requestor in HTML format
By Manica Senapati, Intelligroup
Aim: To Send Workflow Notification to Requestor in HTML Format
Step1:
Create Function module for sending workflow notification in HTML format.
FUNCTION zsend_notif_mail_emp.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(TRIPNO) TYPE BAPITRIP-TRIPNO OPTIONAL
*" REFERENCE(EMP_EMAIL) TYPE ADR6-SMTP_ADDR OPTIONAL
*" REFERENCE(EMP_NAME) TYPE PA0002-CNAME OPTIONAL
*" REFERENCE(APPR_FLAG) TYPE SYST-INPUT OPTIONAL
DATA : it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0 WITH HEADER
LINE,
it_attach TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0 WITH HEADER
LINE,
t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
w_doc_data LIKE sodocchgi1.
w_doc_data-sensitivty = 'F'. "Fill the document data and get size of
attachment
w_doc_data-doc_size = 15 * 255. "Populate the subject/generic message
attributes
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
CONCATENATE 'Your Travel Request' tripno 'has been sent for approval' INTO
w_doc_data-obj_descr SEPARATED BY space.
CLEAR t_receivers.
t_receivers-receiver = emp_email. "Get requestor mail id from table PA0105
based on his PERNR.
t_receivers-rec_type = 'U'.
t_receivers-com_type = 'INT'.
t_receivers-notif_del = 'X'.
t_receivers-notif_ndel = 'X'.
APPEND t_receivers.
REFRESH it_message.
CLEAR it_message.
CONCATENATE '<B><FONT COLOR="RED">'
'*******THIS IS AN SYSTEM GENERATED NOTIFICATION. PLEASE DO NOT REPLY TO THIS
E-MAIL.*******'
'</B><BR>'
INTO it_message. " SEPARATED BY space.
APPEND it_message.
CLEAR it_message.
it_message = '<BR></FONT>'.
APPEND it_message.
CLEAR it_message.
CONCATENATE 'Dear' emp_name '<BR>'
INTO it_message SEPARATED BY space.
APPEND it_message.
CLEAR it_message.
it_message = '<BR>'.
APPEND it_message.
CLEAR it_message.
IF appr_flag = 'A'.
CONCATENATE 'Your travel request' tripno 'has been approved.'
'<BR><BR>'
INTO it_message SEPARATED BY space.
APPEND it_message.
CLEAR it_message.
ELSEIF appr_flag = 'R'.
CONCATENATE 'Your travel request' tripno 'has been denied.' '<BR><BR>'
INTO it_message SEPARATED BY space.
APPEND it_message.
CLEAR it_message.
ELSEIF appr_flag = 'S'.
CONCATENATE 'Your travel request' tripno 'has been returned to you for
corrections.' '<BR><BR>'
INTO it_message SEPARATED BY space.
APPEND it_message.
CLEAR it_message.
ENDIF.
it_message = 'If you have any questions regarding this action, please
contact your supervisor.'.
APPEND it_message.
CLEAR it_message.
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
EXPORTING
document_data = w_doc_data
document_type = 'HTM' " To get the notification in HTML format
commit_work = 'X'
TABLES
object_content = it_message
receivers = t_receivers.
Import Parameters in function module ZSEND_NOTIF_MAIL_EMP:

Step2:
Method to send Notification.
BEGIN_METHOD ZSENDNOTIFMAILEMP CHANGING CONTAINER.
DATA: TRIPNO TYPE BAPITRIP-TRIPNO,
EMPEMAIL TYPE ADR6-SMTP_ADDR,
EMPNAME TYPE PA0002-CNAME,
APPRFLAG TYPE SYST-INPUT.
SWC_GET_ELEMENT CONTAINER 'EmpEmail' EMPEMAIL.
SWC_GET_ELEMENT CONTAINER 'EmpName' EMPNAME.
SWC_GET_ELEMENT CONTAINER 'ApprFlag' APPRFLAG.
tripno = object-key-tripnumber.
CALL FUNCTION 'ZSEND_NOTIF_MAIL_EMP'
EXPORTING
TRIPNO = TRIPNO
EMP_EMAIL = EMPEMAIL
EMP_NAME = EMPNAME
APPR_FLAG = APPRFLAG.
END_METHOD.
Click here to continue...

Sending workflow notification to Requestor in HTML format
...Previous
Step3: Task to call our Method in Workflow.


Step4:
Workflow definition

Step5:
Event Activation (Event Linkage)

Output:
Whenever a trip is created in ESS or in transaction code TRIP, you will get a notification mail in your
inbox as shown below.


Registering WEB DYNPRO/BSP Application with a Workflow Work item
By Gaurang Kotecha, L&T Infotech
Agenda:
This document will help understanding how a web-dynpro/BSP application can be linked to a workflow
work item.
Pre-requisites: It is assumed that the reader of this document has a preliminary understanding of
workflow and web dynpro / BSP application.
Procedure:
1. Run Tcode WF_HANDCUST

You will get all the parameters related to the system. If it is not set click on the change button and
generate automatically will give you all the parameters maintained at the database level for the system.
After doing that click on the Generate URL button and then Test URL to make sure it is working fine.
2. Run Tcode: WF_CPL
Click on New Entries:
Provide following details into the transaction:
Task Workflow Task number to be linked with WEB DYNPRO / BSP PAGES
Directory SAP Workplace/Portal Content Directory
Logical System Logical system name of your system
SAP Release SAP Release of your system
User Name User Name
Service ID Unique Service ID to identify the WEB DYNPRO / BSP Application
3. Run Tcode: WF_EXTSRV
Click on the New Entries:

Provide following details into the transaction:
Service ID Unique Service ID to identify the WEB DYNPRO / BSP Application (same as given in point
2)
Short Text Short text to identify the service
Log HTTP / HTTPS (Based on the requirement)
Host System Host name (From Tcode: WF_HANDCUST)
Port Port number (From Tcode: WF_HANDCUST)
Path Path of the WEB DYNPRO/BSP Page (e.g. /sap/bc/webdynpro/sap/ztestapp)
Call mode Based on the requirement (Mostly used: Dialog Based Service)
4. Setting up the communication parameters:

After adding all the details select the line and select parameters to add import/export parameters details.
Save the configuration and test your scenario.
Summary:
After this configuration is successfully completed, Web forms (WD & BSP) can be opened by opening the
work items. Also if the task is configured with UWL it can directly be opened from the UWL.

Working with Dynamic Task Submission in Workflow
By Gaurang Kotecha, L&T Infotech
Agenda:
This document will help implementing the dynamic submission of tasks in a workflow template.
Pre-requisites: It is assumed that the reader of this document has a preliminary understanding of
workflow and has worked with the task and container elements earlier. If not, please go through the first
two Tutorials of workflow available here. (More details)
All dynamically used tasks for the one workflow step must be having same binding parameters.
Procedure:
1. Create a container element TASKID

2. Assign the container element into the details tab Ad Hoc Specification
Determination Expression of Task

Method to populate the task ID can be designed as required.
Summary:
Making this small piece of development, we can dynamically submit the workflow tasks as required. It
may also help reducing the redundant development of the similar step.

Archiving SAP Work items
By Pratik Vora, Wipro
Introduction
Even the most modern and technologically advanced database systems can suffer from performance
bottlenecks caused by large data volumes. On the application side these bottlenecks manifest
themselves in the form of poor system performance and on the administration side in the form of an
increased use of resources. High data volumes can also have a considerable effect on the Total Cost of
Ownership of a system, in spite of falling storage prices.
To avoid the negative effects of large data volumes on costs, performance and system availability,
business complete data, which is data no longer needed in everyday business processes, should be
removed from the database. However, simply deleting this data is not a useful option in most cases,
because often times the data still needs to be available for read accesses. Therefore the data needs to be
removed from the database and stored in such a way that it can still be read-accessed later.
SAP Data Archiving is the only method supported by SAP to remove application data from the database
in a consistent, secure and comprehensive manner. Consistency is ensured through the use of checks
performed by the archiving programs. A purely database-integrated archiving is not used, because the
database does not know the business context of the data to be archived. Using data archiving you can
select significant objects, such as accounting documents, material master records or HR master data, and
remove them from the database, without having to worry about the fundamental table design of the linked
data.
The archived data is stored in a file system and from there can be moved to other storage media. For
security reasons the archived data is not deleted from the database until the archive files have been read
and hereby confirmed.
Functions
Data Archiving is a process in which system delete the unwanted data for the production system to some
other system, you can think that we have back up option than why data archiving, Now the answer is
there are differences between data archiving and data backup, During the backup we just delete the data
and copy it on some other device or system, following things misses during backup,
1. We do not have any option for validation, means suppose we are deleting some data from PO
Item table but during back up it will not check in PO header table on that case there will be
entry in EKKO table but no entry in EKPO table. System will not be consistent.
2. After back we do not have any link with the back up data, if we want to read some of the data
we do not have any option to read data based on Key field say PO Number.
3. After deleting for some reason if back up fails we do not have option to restore it.
All the above mention points and some other points also removed in Data Archiving process. Now Data
Archiving process is a safe and reliable way to keep your system fast with recent data and up to date with
old data stored in third system.
Now the question is why we need data archiving. In every org. with increasing number of transaction the
size of database increases which leads the system to perform very slow, and expanses of unnecessary
memory ( if we want to increase the performance). We just cannot delete the old data because various
times we need those data, some time in Reporting purpose and sometime during Auditing purpose.
Concept of Data Archiving
Data archiving insure us that after archiving system will not be inconsistent. The concept is same which is
concept of SAP Business Objects (Transaction Code: SWO1). Every Business Objects consist of various
Attributes, Key Fields, Interface and Methods. The concept of business objects is same which the
concept of OPPS Programming is. Lets take an example of Business Object PO (BUS2012), the key
field would be PO Number, Attribute will be Vendor, PO Org etc, the method would be Creation of PO,
Deletion of PO etc. With the help of method we can change the attribute of object means we can change
the PO, we can delete the PO etc.
Now go on a little bit details, If we think about attributes than where these attributes are stored, they are
stored in various transparent tables in SAP with some relations. We cannot store all the attributes of an
object in a single table, concept of Normalization in Data Base. So we have various tables where we are
storing the data and making the validation based on Check Table, Value Table Etc. So for PO we have
various tables say EKKO for PO Header, EKPO for PO Item, EKBE, MARA, MARC, EBAN..and there
is some link among all these tables so the valid records in all the tables can create a business object (
Close to BAPI).
Now We just cannot delete the records of only EKKO because some relation still exist in EKPO, EKBE
Etc Tables. So if we want to delete a record we need to delete all the related entries from all the
dependent tables, and this is the concept of Data Archiving in SAP . In data archiving data cannot be
deleted from the system unless it is successfully copied into third system.
The data archiving process in the SAP system can be divided into the following steps:
1. Data is written to the archive
The data to be archived is read from the database and written sequentially to newly created archive files.
2. Data is deleted from the database
The delete program deletes the data from the database after it has been completely written to the archive
files. To ensure the integrity of the archived data, the delete session is not started until the created
archive files have been read and confirmed.
3. Archive files are stored
The archive files that were created during the write phase can be moved to storage systems or to tertiary
storage media. The storage phase is not part of the actual
Step by step Procedure of Archiving Work Items of workflows:
Workflows are quite bulky in nature as one workflow contains around 40000 lines. Workflow archival
process is slow and sometime does not effectively reduce key tables and new workflow added faster
rates then archival.
The system archives all data (not including runtime data) that belongs to a work item. You can display
archived work items, but you cannot reload them into a system.
You can only archive completed workflow work items. This involves archiving all work items that are
dependent on this workflow work item as well. A work item that depends on superordinate work items
cannot be archived on its own.
You archive log data, workflow manager data, dependent work items and work item attachments (for
example, graphics files).
The other objects in the container of a work item are archived only as references. They are not deleted.
Criteria for Archiving
You can only archive those work items that have one of the following statuses:
Completed
The execution of the work item is completed.
Logically deleted (CANCELLED)
Execution of the work item is no longer useful or required for the workflow logic.
Objective: To Archive Work items which are created between 12.06.2011 and 12.07.2011 and deleting
them from the database.
Steps
1. Customizing Archiving Objects: Transaction ABOJ
We have two options; either we have SAP Standard object / Custom Objects. For both the objects we
have transaction code AOBJ. Object is get the SAP Object which we need to Archive.
Archiving Object: WORKITEM

Double Click it for details. Here you will be able to see or modify write and deletion program names, which
are used for archiving.
The WRITE program is the name of the program which will be used for writing data in to Archive file.
Remember this program will change from object to object. Same for delete and reload programs.

Click here to continue...

Archiving SAP Work items
...Previous
Go to Customizing settings for maintaining Logical File path and Customizing for deletion Jobs.

1. Archiving data: Transaction SARA
Now once you have got the details of the object next step is to configure the system for archiving
process. Lets go a little bit in details. Transaction code is SARA. If you do not put any name in object
you will get the following screen.

As soon as you put the object name there you will get the changed screen. The other attribute it will
collect from AOBJ transaction. For Example if we delete the name of the deleting program from AOBJ
than Delete option will be removed from here also and if you put some new program name there it will
appear here also.
The next screen would be

Before going ahead lets check what are the dependent tables for the object. Click on DATABASE
TABLES. Your screen will be

If you see at the bottom than you will see the name of the tables from which data will be deleted after
archiving.
Now if we want to check what are the tables and these tables are involved in which click on radio button
Object for Tables and put the table name say JEST, on the bottom window you will get the number of
object in which this table is used. Select it and press Show Tables Button you will get the name of the
tables involve in this object.

Click here to continue...

Archiving SAP Work items
...Previous
Lets go ahead with the data archiving.
Now we need to configure the system. Now click on the WRITE option. You will get the following screen.

Create & Maintain variant ZTEST and put suitable conditions as per requirement of archiving strategy.

Maintain Suitable Start time and Spool parameters.

Execute the session, which will create new archiving job. Logs can be seen through Jobs Button.

Archival logs will be displayed in spool request of the job.

As per our configuration Deletion job was also automatically triggered after completion of the writing
action. This also can be seen through Job details.

Now data has been archived into application layer and data is removed from the database layer. Thus
improving significant performance of the system and also marks completion of archiving process for Work
items of the workflow.

Delegate a Subtype to Supertype
By Richa Gupta, Sparta Consulting
Purpose:
When a workflow is created using a Business Object, then sometimes it is needed to customize the
Business Object. In such a case, we need to delegate the customized Business Object to the original
Business Object.
Steps for Delegation:
Go to SWO1 and create a subtype of supertype 'QMSM' by clicking on 'SUBTYPE' button:

Specify the following details :

Now the subtype will be created. Now to create a new method in subtype 'ZQMSM', click on METHODS
and then click on create button:

It will ask you if you want to create method with the help of some existing function module or not. Here,
we will create it with the help of function module 'ZFI_GET_MANAGER'. So click on YES tab:

Specify the function module name and you will get the following screen:

Click on right arrow button until you get the following screen :

Click on method just created and follow the below menu path to release the same:

Also, you need to implement and release the object type as a whole. To do the same, select object type
and follow the below menu path:

Now to delegate the subtype to supertype, go to initial screen of SWO1 and follow the below path:

Go into change mode and select NEW ENTRIES tab to create a new entry :

Specify the following details:

Save the entry and assign it to a TR.

Demo on Workflow using Classes
By Richa Gupta, Sparta Consulting
Purpose
To develop workflow using OOPS concept instead of using standard Business Object.
NOTE: Before following this document, one must have a basic knowledge of OOPS Concepts.
Steps to follow to use Classes in Workflow

How to Create Custom Class
Here we will be creating a custom class for MATERIAL.
Go to transaction SE24 and create a customized class.

Next the pop up appears where we need to mention the detail as follows:

Save it and the class is created.
Now the class is to implement IF_WORKFLOW interface. For this go to the tab and
declare the IF_WORKFLOW as the interface there and press Enter; two sub-interfaces
appear: BI_OBJECT and BI_PERSISTENT. Save the Class.

The ZCL_TEST class now contains the existing methods of IF_WORKFLOW interface.

Also, 2 new interfaces will be automatically added once you add IF_WORKFLOW interface in the class as
shown below:

Each method of the IF_WORKFLOW Interface has its distinct functionality, which is discussed below.
BI_PERSISTENT~FIND_BY_LPOR Method:

Here, to create object, constructor of class needs to be implemented as follows:

Here, SET_ATTRIBUTES method is called which will be implemented as follows :

Click here to continue...

Demo on Workflow using Classes
...Previous
BI_PERSISTENT~LPOR Method:

BI_PERSISTENT~REFRESH Method:
If we do not need the method in our class, then we need only to carry out a dummy implementation
(without further coding) to avoid program errors when the system calls the method.

BI_OBJECT~DEFAULT_ATTRIBUTE_VALUE Method:

BI_OBJECT~EXECUTE_DEFAULT_METHOD Method:

BI_OBJECT~RELEASE Method:

Now, the attributes need to be developed to implement above methods are as follows:

To trigger the workflow using event of class, we must also create an event of the class. To do this, go to
EVENTS tab, and there create a new event CREATED as shown below :

Before implementing above methods, a local type needs to be created. To do this, click on LOCAL
TYPES as shown below:

Now write the below code :

How to use Class in a Workflow
Here, the workflow needs to be triggered as soon as a material is created. And then a workitem should go
to initiator to edit the same material.
Go to SWDD to create a new workflow.
Click on Basic Data Tab :

Give an abbreviation and Short Description to workflow as follows :

Now click on START EVENTS tab and specify the following standard event of the standard class :

Now go back and right click in between the WORKFLOW STARTED and WORKFLOW COMPLETED.

Click here to continue...

Demo on Workflow using Classes
...Previous
Select CREATE. A list of available step types will be displayed as follows:

Select ACTIVITY from this list. The following screen will appear:

Specify the following details here:

Click on Binding tab. Binding will be as follows:

Click on task description. Automatically following details will show :

Click on the green button for binding above and confirm the bindings must be as follows :

SET AGENT ASSIGNMENT:
Click on yellow button coming besides Agent Assignment :

Click here to continue...

Demo on Workflow using Classes
...Previous
Select CREATE. A list of available step types will be displayed as follows:

Select ACTIVITY from this list. The following screen will appear:

Specify the following details here:

Click on Binding tab. Binding will be as follows:

Click on task description. Automatically following details will show :

Click on the green button for binding above and confirm the bindings must be as follows :

SET AGENT ASSIGNMENT:
Click on yellow button coming besides Agent Assignment :

Click here to continue...

Demo on Workflow using Classes
...Previous
Select CREATE. A list of available step types will be displayed as follows:

Select ACTIVITY from this list. The following screen will appear:

Specify the following details here:

Click on Binding tab. Binding will be as follows:

Click on task description. Automatically following details will show :

Click on the green button for binding above and confirm the bindings must be as follows :

SET AGENT ASSIGNMENT:
Click on yellow button coming besides Agent Assignment :

Click here to continue...

Demo on Workflow using Classes
...Previous
Select CREATE. A list of available step types will be displayed as follows:

Select ACTIVITY from this list. The following screen will appear:

Specify the following details here:

Click on Binding tab. Binding will be as follows:

Click on task description. Automatically following details will show :

Click on the green button for binding above and confirm the bindings must be as follows :

SET AGENT ASSIGNMENT:
Click on yellow button coming besides Agent Assignment :

Click here to continue...

Demo on Workflow using Classes
...Previous
Select CREATE. A list of available step types will be displayed as follows:

Select ACTIVITY from this list. The following screen will appear:

Specify the following details here:

Click on Binding tab. Binding will be as follows:

Click on task description. Automatically following details will show :

Click on the green button for binding above and confirm the bindings must be as follows :

SET AGENT ASSIGNMENT:
Click on yellow button coming besides Agent Assignment :

Click here to continue...

Demo on Workflow using Classes
...Previous
Select CREATE. A list of available step types will be displayed as follows:

Select ACTIVITY from this list. The following screen will appear:

Specify the following details here:

Click on Binding tab. Binding will be as follows:

Click on task description. Automatically following details will show :

Click on the green button for binding above and confirm the bindings must be as follows :

SET AGENT ASSIGNMENT:
Click on yellow button coming besides Agent Assignment :

Click here to continue...

Demo on Workflow using Classes
...Previous
Select CREATE. A list of available step types will be displayed as follows:

Select ACTIVITY from this list. The following screen will appear:

Specify the following details here:

Click on Binding tab. Binding will be as follows:

Click on task description. Automatically following details will show :

Click on the green button for binding above and confirm the bindings must be as follows :

SET AGENT ASSIGNMENT:
Click on yellow button coming besides Agent Assignment :

Click here to continue...

Demo on Workflow using Classes
...Previous
Select CREATE. A list of available step types will be displayed as follows:

Select ACTIVITY from this list. The following screen will appear:

Specify the following details here:

Click on Binding tab. Binding will be as follows:

Click on task description. Automatically following details will show :

Click on the green button for binding above and confirm the bindings must be as follows :

SET AGENT ASSIGNMENT:
Click on yellow button coming besides Agent Assignment :

Click here to continue...

Demo on Workflow using Classes
...Previous
Select CREATE. A list of available step types will be displayed as follows:

Select ACTIVITY from this list. The following screen will appear:

Specify the following details here:

Click on Binding tab. Binding will be as follows:

Click on task description. Automatically following details will show :

Click on the green button for binding above and confirm the bindings must be as follows :

SET AGENT ASSIGNMENT:
Click on yellow button coming besides Agent Assignment :

Click here to continue...

Demo on Workflow using Classes
...Previous
Select CREATE. A list of available step types will be displayed as follows:

Select ACTIVITY from this list. The following screen will appear:

Specify the following details here:

Click on Binding tab. Binding will be as follows:

Click on task description. Automatically following details will show :

Click on the green button for binding above and confirm the bindings must be as follows :

SET AGENT ASSIGNMENT:
Click on yellow button coming besides Agent Assignment :

Click here to continue...

Demo on Workflow using Classes
...Previous
Select CREATE. A list of available step types will be displayed as follows:

Select ACTIVITY from this list. The following screen will appear:

Specify the following details here:

Click on Binding tab. Binding will be as follows:

Click on task description. Automatically following details will show :

Click on the green button for binding above and confirm the bindings must be as follows :

SET AGENT ASSIGNMENT:
Click on yellow button coming besides Agent Assignment :

Click here to continue..

Demo on Workflow using Classes
...Previous
Select CREATE. A list of available step types will be displayed as follows:

Select ACTIVITY from this list. The following screen will appear:

Specify the following details here:

Click on Binding tab. Binding will be as follows:

Click on task description. Automatically following details will show :

Click on the green button for binding above and confirm the bindings must be as follows :

SET AGENT ASSIGNMENT:
Click on yellow button coming besides Agent Assignment :

Click here to continue...

Demo on Workflow using Classes
...Previous
Select CREATE. A list of available step types will be displayed as follows:

Select ACTIVITY from this list. The following screen will appear:

Specify the following details here:

Click on Binding tab. Binding will be as follows:

Click on task description. Automatically following details will show :

Click on the green button for binding above and confirm the bindings must be as follows :

SET AGENT ASSIGNMENT:
Click on yellow button coming besides Agent Assignment :

Click here to continue...

Demo on Workflow using Classes
...Previous
Select CREATE. A list of available step types will be displayed as follows:

Select ACTIVITY from this list. The following screen will appear:

Specify the following details here:

Click on Binding tab. Binding will be as follows:

Click on task description. Automatically following details will show :

Click on the green button for binding above and confirm the bindings must be as follows :

SET AGENT ASSIGNMENT:
Click on yellow button coming besides Agent Assignment :

Click here to continue...

Demo on Workflow using Classes
...Previous
Select CREATE. A list of available step types will be displayed as follows:

Select ACTIVITY from this list. The following screen will appear:

Specify the following details here:

Click on Binding tab. Binding will be as follows:

Click on task description. Automatically following details will show :

Click on the green button for binding above and confirm the bindings must be as follows :

SET AGENT ASSIGNMENT:
Click on yellow button coming besides Agent Assignment :

Click here to continue...

Demo on Workflow using Classes
...Previous
Select CREATE. A list of available step types will be displayed as follows:

Select ACTIVITY from this list. The following screen will appear:

Specify the following details here:

Click on Binding tab. Binding will be as follows:

Click on task description. Automatically following details will show :

Click on the green button for binding above and confirm the bindings must be as follows :

SET AGENT ASSIGNMENT:
Click on yellow button coming besides Agent Assignment :

Click here to continue...

Demo on Workflow using Classes
...Previous
Select CREATE. A list of available step types will be displayed as follows:

Select ACTIVITY from this list. The following screen will appear:

Specify the following details here:

Click on Binding tab. Binding will be as follows:

Click on task description. Automatically following details will show :

Click on the green button for binding above and confirm the bindings must be as follows :

SET AGENT ASSIGNMENT:
Click on yellow button coming besides Agent Assignment :

Click here to continue...

Sending multiple attachment in user decision step of workflow
By Lokesh Tripathi, Infosys
Business Requirement
This document describes how to send multiple attachments in the user decision step of the workflow.
User can see multiple attachments and based on that take the necessary required decision.
This method would be helpful in business processes where user wants to introduce approval step before
processing or accepting any finance report or other document.
Functional Specification
User will execute the custom report/transaction that will trigger the workflow (we can associate starting
event also to this workflow).
Workflow will send mail having multiple attachments to SAP Inbox as a user decision.
Based on user decision rest logic would happen.
Workflow Flow Diagram


Technical Specification

For adding attachments in the user decision steps method EVENT_RAISED of interface
IF_SWF_IFS_WORKITEM_EXIT needs to be implemented and it is used as a Function Exit in the user
decision step.



Go to SE24, implement method EVENT_RAISED of interface IF_SWF_IFS_WORKITEM_EXIT
ZTEST_WFATTACH is created for the same.




In this method code for inserting attachments needs to be implemented (Please use below code for the
same)
First check whether workflow container already have any attachments or not to avoid any duplications.

* Fetch the workflow work item Id
CALL METHOD IM_WORKITEM_CONTEXT->GET_WORKITEM_ID
RECEIVING
RE_WORKITEM = LV_ID.

* Fetch Container
CALL METHOD IM_WORKITEM_CONTEXT->GET_WI_CONTAINER
RECEIVING
RE_CONTAINER = LV_CONTAINER.
* Read attachment to confirm that there is no duplication
CLEAR LV_OBJ_RECORD.
CALL METHOD LV_CONTAINER->GET
EXPORTING
NAME = '_ATTACH_OBJECTS'
IMPORTING
VALUE = LV_ATTACH.
IF LV_ATTACH IS INITIAL.

If there are no prior attachments then identify the folder id based on sy-user


CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'
EXPORTING
OWNER = SY-UNAME
REGION = 'B'
IMPORTING
FOLDER_ID = LV_FOLDER_ID.

In this scenario we are converting spool output to PDF and attaching the same PDF in the user decision
step

Give spool number in LV_SPOOL field

CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
SRC_SPOOLID = LV_SPOOL
NO_DIALOG = ''
PDF_DESTINATION = 'X'
IMPORTING
PDF_BYTECOUNT = LA_BYTE_COUNT
TABLES
PDF = GT_PDF
EXCEPTIONS
ERR_NO_ABAP_SPOOLJOB = 1
ERR_NO_SPOOLJOB = 2
ERR_NO_PERMISSION = 3
ERR_CONV_NOT_POSSIBLE = 4
ERR_BAD_DESTDEVICE = 5
USER_CANCELLED = 6
ERR_SPOOLERROR = 7
ERR_TEMSEERROR = 8
ERR_BTCJOB_OPEN_FAILED = 9
ERR_BTCJOB_SUBMIT_FAILED = 10
ERR_BTCJOB_CLOSE_FAILED = 11
OTHERS = 12.

LOOP AT GT_PDF INTO LWA_PDFLINE.
ASSIGN LWA_PDFLINE TO <L_XLINE> CASTING.
CONCATENATE PDF_XSTRING <L_XLINE>
INTO PDF_XSTRING IN BYTE MODE.
ENDLOOP.

* Create and set document
IT_SOLIX_TAB1 = CL_DOCUMENT_BCS=>XSTRING_TO_SOLIX (PDF_XSTRING).

Creating First attachment

LV_DATA-OBJ_NAME = 'Test Sending Attachments'.
LV_DATA-OBJ_DESCR = 'Attachment 1'.
LV_DATA-OBJ_LANGU = SY-LANGU.
LV_DATA-SENSITIVTY = 'P'.
LV_DATA-DOC_SIZE = LA_BYTE_COUNT.


CALL FUNCTION 'SO_DOCUMENT_INSERT_API1'
EXPORTING
FOLDER_ID = LV_FOLDER_ID
DOCUMENT_DATA = LV_DATA
DOCUMENT_TYPE = 'PDF'
IMPORTING
DOCUMENT_INFO = WA_DOCUMENT_INFO
TABLES
CONTENTS_HEX = IT_SOLIX_TAB1
EXCEPTIONS
FOLDER_NOT_EXIST = 1
DOCUMENT_TYPE_NOT_EXIST = 2
OPERATION_NO_AUTHORIZATION = 3
PARAMETER_ERROR = 4
X_ERROR = 5
ENQUEUE_ERROR = 6
OTHERS = 7.
* Populate object type and object key for create an instance
LV_OBJTYPE = 'SOFM'.
LV_OBJKEY = WA_DOCUMENT_INFO-DOC_ID.

Creating SOFM object

CALL FUNCTION 'SWO_CREATE'
EXPORTING
OBJTYPE = LV_OBJTYPE
OBJKEY = LV_OBJKEY
IMPORTING
OBJECT = LV_SOFM
RETURN = LV_RETURN
EXCEPTIONS
NO_REMOTE_OBJECTS = 1
OTHERS = 2.

* Prepare for attaching the object to container
LV_OBJJECT-HEADER = 'OBJH'.
LV_OBJECT-TYPE = 'SWO'.
LV_OBJECT-HANDLE = LV_SOFM.
APPEND LV_OBJECT to TB_OBJ.

Similarly prepare other attachments and append their details to tb_obj internal table.
Finally send the attachment details in the task container

CALL METHOD LV_TAKS_CONTAINER->SET
EXPORTING
NAME = '_ATTACH_OBJECTS'
VALUE = TB_OBJ[].

* Commit the changes
CALL METHOD IM_WORKITEM_CONTEXT->DO_COMMIT_WORK.
Click here to continue...
Sending multiple attachment in user decision step of workflow
...Previous
Now create the workflow in SWDD and in the user decision step give class ZTEST_WFATTACH as a
program exit.

Program exit would get triggered whenever user step is executed by the user.
Binding of user decision step:


Execution:
Once workflow is created you can associate with any event or you can directly execute it to check the
result.




After reviewing the document user can take the necessary decision.

Demo on working with "Nested / SubWorkflows"
By Avinash Palavai, StraVis IT Solutions
Prerequisite : Should have basic idea of worklow and usage of Send Mailand Activity Steps.
1) Go to the transaction SWDD ( Workflow Builder ). By default, it opens the last developed workflow. So
click on create to create a new Workflow. Below screen appears.

2) Now create a step Send Mail, by double clicking on Undefined Step.

3) Now the below screen appears and, fill the screen as shown below and click on Transfer and to
graphic ( ).

4) Now a pop up appears and give the abbreviation and name of the task as below,

5) Your workflow will look like below,

6) Save and activate the workflow, now a workflow no. will be assigned to your workflow as shown
below,

7) Now again create a new workflow, repeating the steps (1 & 2) and fill the Send Mail step as below,

8) This time give the name as Main workflow as shown below,

9) Your 2
nd
workflow (Main Workflow) would now appear as below and create an additional step
Activity to trigger the sub workflow.


Click here to continue...

Demo on working with "Nested / SubWorkflows"
...Previous
10) Now the below screen appears enter the Sub workflow no. (WS99900005) i.e., created above and
the step name as shown below and click on Transfer and to graphic ( ).

11) This is how your main Workflow looks like,

12) Save and activate and a Workflow no. will be generated as shown below,

13) Now you can test run the workflow, by clicking on the test ( ), and the below test screen ppears.

14) Click on execute ( ). Now your main workflow and the subworkflow nested in it is also executed.
15) Go to your Business workplace (SBWP) and check the inbox. You will find two mails with the titles
Mail in Main Workflow triggered from main WF and Mail in Sub Workflow triggered from Sub WF.


Call instance method from workflow using class
By Rakesh Dhudipala
Scenario:
Below document explains how to call instance Method from Workflow task
Prerequisites:
ABAP objects
Step by step Procedure:
Go to SE24, create a class by name ZCL_TEST_WORKFLOW.

Implement interface IF_WORKFLOW in the class.

Create one instance method called GET_RESULT

Define below attributes in the Attributes TAB

Create below methods in the methods tab.

1) Constructor:
Define with below parameters.

In the 'Constructor' write the below code.
method CONSTRUCTOR.

m_lpor-INSTID = i_id.
m_lpor-CATID = 'CL'.
m_lpor-TYPEID = 'ZCL_TEST_WORKFLOW'.
endmethod.
2) GET_RESULT:
Method contains below parameters.

Write the below code in the GET_RESULT method.
method GET_RESULT.
p3 = p1 * p2.
endmethod.
3) Create:
Create method contains below parameters.
Write the below logic in the CREATE method.
method CREATE.
CREATE OBJECT e_instance
TYPE
zcl_test_workflow
EXPORTING
i_id = i_id.
endmethod.
In BI_PERSISTENT~FIND_BY_LPOR interface method write the below code
method BI_PERSISTENT~FIND_BY_LPOR.
CREATE OBJECT result
TYPE
zcl_test_workflow
EXPORTING
i_id = lpor-instid(10).
endmethod.
In the BI_PERSISTENT~LPOR method write the below code
method BI_PERSISTENT~LPOR.
result = me->M_Lpor.
endmethod.
Click here to continue...

Call instance method from workflow using class
...Previous
Go to SWDD transaction and create new workflow.

Create new activity

Create new task and enter the CREATE method

This will map the below parameters

Create one more task and enter the get_result method in the task like below

Now container mapping with the below parameters

Assign the agents to the task

Make task as general task

Now if we run the workflow it will executes the instance method.

Display Dynamic Attachments in Work Item in Workflow
By Anirban Bhattacharjee, KPIT Cummins and Infosystems
Purpose: The purpose of this article is to show you how to display dynamic attachments in work items in
workflow
Business Scenario: This is useful in all workflows across all modules. The scenario I am taking for an
example is the Travel and Expense Workflow, related to the PR05 and TRIP transactions. When an
employee creates an expense report in the T&E Module, he needs to attach receipts to justify the
expense. The application in R/3 (PR05 / TRIP) or the ESS MSS Application via portal processes this
attachment to the GOS Attachments folder. After the attachment the employee submits the TRIP which
triggers the workflow and routes the work item for approval. In the workflow just before the foreground
work item creation, we can read the GOS Folder and attach the documents as a physical attachment.
But many times the employee forgets to do the attachment and completes it after TRIP submission and
hence work-item creation. The approver now cannot see this new document attached after workflow
trigger and TRIP Submission.
This article will show how to make this happen. You will be able to enable a feature such that
approvers can view all attachments done after TRIP Submission and hence the workflow trigger.
Process: The process will involve the following steps
Create a custom business object that will read the GOS Attachment. This method will be called as
the default method in the BOR.
Create a custom workflow for demo. In this workflow we will use the main SAP Business Object for
TRIP; BUS2089 (Employee Trip).
We will instantiate the custom BOR in the workflow and attach it to the _ADHOC_OBJECT element
to create the dynamic GOS attachment link.
We can test in Business Workplace (SBWP) or the UWL in Portal if you have portal in your project.
STEP 1: Create a Custom Business Object
(I am not going into the details of business object creation. That is not in this document scope)
We call this business object as ZTRIP_NEW (Display TRIP Attachments in Real Time).

We create a method GOS_ATTACH_DISPLAY as shown below

(Please overlook the other methods. They are not related to this topic)
This method has no parameters

This is an instance depended method, that is the BOR must be instantiated to call this method

In order to display the GOS Attachments, we will call the function
module GOS_ATTACHMENT_LIST_POPUP.
Here we will pass the importing parameter IP_MODE as D to ensure that the attachments can only be
displayed.
The approver should not be able to add or remove any attachments.
The code you will write in this method is shown below
begin_method gos_attach_display changing container.

DATA: is_object TYPE sibflporb.

is_object-typeid = 'BUS2089'.
is_object-catid = 'BO'.
is_object-instid = object-key.
* GOS Attachments
CALL FUNCTION 'GOS_ATTACHMENT_LIST_POPUP'
EXPORTING
is_object = is_object
ip_check_arl = 'X'
ip_check_bds = 'X'
ip_notes = 'X'
ip_attachments = 'X'
ip_urls = 'X'
ip_mode = 'D'
* IMPORTING
* EP_SAVE_REQUEST =
* TABLES
* IT_OBJECTS =
.
end_method.
Please note that we are building the TRIP key here along with Business Object (BUS2089 for TRIP) and
Category ID (BO for Business Object).
This function module will read this unique key combination of the instance (TRIP and Employee Number)
with the Business Object ID and Cat ID and display the attachment list.
Now once the method is created, we will mark this method as a default method. I will explain later why we
are doing this.
In the BOR Screen, navigate to the Basic Data (CTRL+SHIFT+F1) of the BOR by clicking on the HAT
Icon as shown

We navigate to this screen now. Click on the DEFAULTS Tab

Enter the Method GOS_ATTACH_DISPLAY and pass attribute as TRIP Number. This will display in the
work item as a link

We save and activate the BOR and mark the method and the BOR as Implemented and Released.
(This is a standard process to be followed when creating a custom BOR).
The above process completes our first step of creating and activating or Custom BOR that will read the
GOS attachment.
STEP 2: Create a Custom Workflow
We will create a custom workflow with simply two steps.
The first step will instantiate our custom BOR, second step will be the user decision that will be sent to the
approver.
The workflow will be modeled on the standard SAP business object BUS2089 as the main business
object.
Run PFTC and create the workflow template, name it as shown and save it

Click here to continue...

Display Dynamic Attachments in Work Item in Workflow
...Previous
Navigate to the container tab and create a container element called TRIP as shown

Mark this element as importing and mandatory

The element is created. Now navigate back to Basic Data to enter the work item text

Save the template and then click on Workflow Builder, to call the builder to design the workflow

STEP 3: Instantiate the Custom Business Object and continue the workflow creation.
Now we will create a background task / activity to instantiate our custom business object ZTRIP_NEW.
In this step we will use a standard task where we will call the method GENERICINSTANTIATE from
BOR SYSTEM as shown

The container element created for this task from method GENERICINSTANTIATE are shown below

OBJECTKEY: Points to SWOTOBJID- OBJKEY. This will contain the TRIP Keys. Has no initial value.

OBJECTTYPE: Points to SWOTOBJID- OBJTYPE. It will contain the Business Object that needs to be
instantiated.
In this case, it is ZTRIP_NEW; hence this will be the default value


OBJECTINSTANCE: This contains no reference to any BOR. This will get the instance of the BOR
specified at runtime.
In this case the BOR passed via OBJECTTYPE is ZTRIP_NEW. Hence the
element OBJECTINSTANCE will contain the instance of this custom BOR.

Click here to continue...

Display Dynamic Attachments in Work Item in Workflow
...Previous
The binding in the method in task is shown

Now the task is created. Save it and come back to the workflow. The workflow prompts for the auto
bindings

Accept and save the bindings


In the workflow, mark this container OBJECTKEY as importing. While testing pass the concatenated
string of Employee Number and TRIP No.
(This is done to simplify the demo. In real time, this key can be built from the event call via event
containers)

Now create an element container to store the above instance for ZTRIP_NEW as shown.
Save this element and the workflow

Now go back to the task created and bind this element created as shown

This will pass the run time instance of our custom business object ZTRIP_NEW to the container we
created of the same name.
Now use container operation step to pass this instance to the Standard Workflow container
element _ADHOC_OBJECTS


Note that I have simply extended the table.
The container _ADHOC_OBJECTS by default will also contain the default method of our Main Standard
SAP Business Object BUS2089.
We are simply extending the table to call our GOS Dynamic BOR as well.
The effect will be in the work item we will get two links one for the standard BOR and one for our custom
BOR.
Important: Whenever you pass the instance of any business object to this
element _ADHOC_OBJECTS, it creates a link in the work item.
On clicking this link, it executes the Default Method of the BOR. This is the reason why we marked
our method GOS_ATTACH_DISPLAY as default.
You can pass the instance of the standard BOR BUS2089 also to this container as shown

Click here to continue...

Display Dynamic Attachments in Work Item in Workflow
...Previous
Now create the USER Decision Step and send to Initiator (For DEMO Simplicity)

Final workflow looks as shown

Our DEMO is now ready to be tested.
First let us display a TRIP via PR05 and see what is there in the attachments

Display attachment via the menu path as shown


So this TRIP has only one attachment now.
We run T-Code SWUS to test the workflow.
Pass the TRIP Details and concatenated data of PERNR and TRIP

Work item in SBWP

Note under Objects and Attachments, we see both the attachments links.
The first link for the Standard Display Method in standard BOR and second link points to our Custom
BOR for Dynamic Links.
Click the Display Attachments Link



Display Dynamic Attachments in Work Item in Workflow
...Previous
We can see one attachment here. Now we go and attach one more attachment in the TRIP as shown

Now coming back to the same work item

Click on the Display Attachments link again. It should show the new attachment also


So we have successfully configured Dynamic Attachments in the workflow.
Clicking on the link Employee TRIP will display the TRIP since BUS2089 has Display Method as Default

The TRIP Gets Displayed


Modify the run-time value of workflow containers
By Anirban Bhattacharjee, KPIT Cummins and Infosystems
Purpose: The purpose of this document is to demonstrate how to modify the values of workflow
containers from the workflow logs running instance. This means, you can actually modify and manipulate
the workflow runtime values after the workflow has triggered and the work items are created. This will
help you restore stuck workflow instances even when the SWPRtransaction cannot restore.
Business Scenario: This manipulation has a number of uses, but for our demo we will consider the
following scenario. In the workflow to send e-mails to outlook we use the send-mail step in the workflow.
The e-mail ID is generally retrieved via a background task prior to calling the send mail step. This e-mail
ID is retrieved from SU01 (User Master) or Info-Type 105 (Communication Info Type) Subtype 10. Many
times it happens that the business forgets to maintain the e-mail ID. The e-mail ID is not retrieved thus
and the e-mail step in the workflow goes into error putting the whole workflow into ERROR status. Simply
running SWPR (Restart Workflow after ERROR) T-Code after maintaining the e-mail ID will also not help
since the e-mail retrieving step has already executed and workflow is stuck at the e-mail sending step.
Restarting the complete workflow will not be acceptable to the business since it will start the approval
process again from the start, thus wasting precious business time.
It is at this difficult scenario, this container manipulation technique will come to your rescue.
Process: To set up a demo for this we will have the following steps
Build a custom workflow with just a send e-mail step with the e-mail field as importing. (Simplified for
demo purpose)
Test-run this demo workflow via SWUS T-Code but do not pass the e-mail ID. This will put the
workflow in ERROR status.
We will simply use SWPR T-Code first to try and restart the workflow instance. This will fail.
We will then modify the workflow runtime container and pass the e-mail ID.
We will restart the workflow via SWPR again. It will work this time.
We can check in SOST to see that e-mail is sent via SAP-Connect.
Pre-requisites: To follow and set up this demo, following are the pre-requisites
You should know how to build a basic workflow with the send e-mail step.
SCOT and SAP Connect must be configured for e-mail sending.
All other workflow configurations via SWU3 are already done.
Building the Custom Workflow with the send e-mail step
The e-mail ID container created is as shown below. It is marked as importing, but not mandatory


The e-mail step will contain this container EMAILID as the e-mail ID variable

After building the custom workflow with the send e-mail step, it will look as shown below

Click here to continue..

Modify the run-time value of workflow containers
...Previous
Testing the demo workflow
Now run SWUS T-Code and enter this workflow template ID to test. Test run the workflow without passing
the e-mail ID (simulates missing e-mail ID).
It will look as shown below

Now we will check the workflow log. We can see that the workflow is in error

The Step History of the work item will tell us that the method to send mail could not execute


The container shows that there is no e-mail ID in the Address Strings field

Now we will run SWPR to attempt to restart this workflow instance. The work item ID is 2733489 for the e-
mail step.
The work item ID of the workflow (Parent ID) is 2733488. Enter that in SWPR


Now select the above row and click on Restart Workflow push button on the application tool bar

The application confirms that the restart has been carried out. Press REFERSH button to see if the restart
was a success

We can see the item is still there. Looking at the workflow log and step history, we see that the workflow
went into ERROR even after the restart

Click here to continue..
Modify the run-time value of workflow containers
...Previous
Note that the restart operation is shown, but still it went into error after that.

So simply running SWPR transaction will not work in this case.
Modify the container value at run time:
To modify the workflow container value, we need to run the function module
SWL_WI_CONTAINER_MANIPULATE
This powerful function module allows you to pass the work item ID of the step whose container you want
to modify.
You can display and edit the containers. In our case, the work item ID of the e-mail step is 2733489

Pass this work item ID to the function module as shown. Do not pass anything to the DISPLAY parameter

Now on executing this function module, the complete container list of the work item step is shown in EDIT
Mode!!
This is the Container Instance Editor

Now select the container Recipient Name and pass a valid e-mail ID. In business scenario, you can get it
from user master (SU01) or Info Type 105 Subtype 10.
Select the container and click on APPEND ROW

Enter the e-mail ID

Now press the ENTER key to accept the changes on the pop-up

Click here to continue..

Modify the run-time value of workflow containers
...Previous
Now go back to the workflow log and refresh to see if the e-mail ID shows up there.
BEFORE REFRESH: Address Strings is empty

AFTER REFRESH: Address Strings has the e-mail ID now (shows as 1 entry and appears on the
overview below)

The workflow is still in error. So we run SWPR again

We press the REFRESH to see if the restart was a success

The item has gone away, indicates a success. We will verify from the workflow log

Note that the workflow has executed the step without errors. Note also that container value change
operation is also captured in the logs.

Showing the graphical log to verify

The active-x log is also show

Running SOST T-Code, to see if the e-mail is out

Conclusion: Thus with this process, we were successfully able to modify and manipulate a workflow
container value from the runtime instance and also successfully restart the workflow instance exactly from
the point where it went into error.
Disclaimer: Use this function module with caution. Be very careful while changing the container values.
Only workflow administrators should do it. Please remember, you activity is logged in the workflow logs,
hence perform the activity only when the workflow is stuck in error and there is no option to restart from
the very beginning.

Capture Rejection Reason Text from User Decision in Workflow
By Anirban Bhattacharjee, KPIT Cummins and Infosystems
Purpose: The purpose of this document is to capture the rejection reason text from the user decision
step in workflow.
Business Scenario: When a user decision with the APPROVE and REJECT options are sent to the
approver, there always comes a business need to allow the user to enter a Rejection Reason text, when
the approver does a rejection. In the older SAP Releases, the standard User Decision step did not have a
process to capture the rejection reason. The latest release of SAP includes this feature.
In this document we will see how to use this feature and capture the rejection reason text and also pass it
to an e-mail sending step. This e-mail we can send to the original requestor so that he gets to know the
cause of the rejection and resubmit for approval after the necessary corrections.
Process: This demo creation will involve the following steps
Create a user decision step with APPROVE and REJECT options and model the Rejection Reason
only for the REJECT Branch.
Capture the rejection reason text and pass to an e-mail sending step via a container.
Pre-requisites: There are a few pre-requisites before doing this demo.
You should know how to build a basic workflow with the send e-mail step and user decision step.
(SAP Technical.Com already has these tutorials)
SCOT and SAP Connect must be configured for e-mail sending.
All other workflow configurations via SWU3 are already done.
You know how to create methods in a custom BOR and call in workflows. (These will not be covered
in details)
Create Custom Workflow and Method to read the REJ ECTION Reason for Demo
(Please read the tutorials on creation of Custom BOR/Method and Custom Workflow with user decisions
and e-mail sending steps in SAP Technical.Com to get the details)
We create the user decision step and mark the two branches APPROVE and REJECTED as shown

Notice that in the latest SAP version, we have an option to configure the Rejection / Approval reasons.
You can use this for any reason you want as per the branch you have created.

We can mark the Reason as Mandatory or Required.

Mandatory: This means, that the Reason has to be mandatorily entered when the corresponding action
is performed, else the user decision work item cannot be completed.
Required: This means, that entering the Reason is optional. The pop-up to enter the reason will appear,
but it is not needed to enter anything to complete the work item.
Here we will mark this Reason as MANDATORY for our REJECT Branch as shown

The step is saved. When the user enters the Reason, it will get appended into
the _ATTACH_OBJECTS standard container of the workflow.

This multiline element points to the SOFM Business Object.
We will now write a method to read this attachment and transfer to a text string.
This method will be an instance independent method. This means, it can be called without instantiating
the BOR.

The parameters for this method are shown below

Click here to continue..

Capture Rejection Reason Text from User Decision in Workflow
...Previous
The details of the parameters are
Parameter WORKITEMID:

Parameter REASON_TXT:

We will be passing the work item ID of the workflow and this method will read the
container _ATTACH_OBJECTS and pass the Rejection Text to variable REASON_TXT.
The code that you will write in the method is given below: (You can write your own code to read and
process the SOFM Attachment Object as per your need)
begin_method read_rejection_reason changing container.

DATA: reason_txt TYPE swcont-value,
reason TYPE swc_object OCCURS 0,
object_content LIKE solisti1 OCCURS 0,
workitemid LIKE swr_struct-workitemid,
subcontainer_all_objects LIKE TABLE OF swr_cont,
lv_wa_reason LIKE LINE OF subcontainer_all_objects,
lv_no_att LIKE sy-index,
document_id LIKE sofolenti1-doc_id,
return_code LIKE sy-subrc,
ifs_xml_container TYPE xstring,
ifs_xml_container_schema TYPE xstring,
simple_container LIKE TABLE OF swr_cont,
message_lines LIKE TABLE OF swr_messag,
message_struct LIKE TABLE OF swr_mstruc,
subcontainer_bor_objects LIKE TABLE OF swr_cont.

swc_get_table container 'REASON' reason.
swc_get_element container 'WORKITEMID' workitemid.

* Read the work item container from the work item ID
CALL FUNCTION 'SAP_WAPI_READ_CONTAINER'
EXPORTING
workitem_id = workitemid
language = sy-langu
user = sy-uname
IMPORTING
return_code = return_code
ifs_xml_container = ifs_xml_container
ifs_xml_container_schema = ifs_xml_container_schema
TABLES
simple_container = simple_container
message_lines = message_lines
message_struct = message_struct
subcontainer_bor_objects = subcontainer_bor_objects
subcontainer_all_objects = subcontainer_all_objects.

* Initialize
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 the SOFM Document
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 reason_txt INDEX 1.
SHIFT reason_txt BY 5 PLACES LEFT.
swc_set_element container 'REASON_TXT' reason_txt.
ENDIF.

end_method.
Note that the method we created, READ_REJECTION_REASON can be executed even without
instantiating the BOR

The above method will be called in a standard task and called in the REJECT branch of the user decision
step.
Click here to continue..

Capture Rejection Reason Text from User Decision in Workflow
...Previous
The standard task will look like as shown below

The binding in this standard task

The binding in the workflow to this task is shown as below

Predecessor work item will contain the Work Item ID of the User Decision Step.
The user decision step is just the previous step to this background step in this workflow template.
The workflow will look like as shown below after adding the above step in the REJECT branch of the User
Decision

Now we will create an e-mail step after this Read Rejection Reason Text. Here we will pass our text and
send as an e-mail.
For simplicity of the demo, I will be hard-coding a dummy e-mail ID to the send e-mail step.

After this process, the complete workflow template will look as shown below

Click here to continue..
Capture Rejection Reason Text from User Decision in Workflow
...Previous
We have not modeled anything for APPROVED branch, since we are show casing only the Rejection
Reason.
You can model the APPROVE or any other branch as per your business need.
We are now ready to test the workflow.
We will run transaction SWUS to test the workflow

We run the user decision from business workplace SBWP

Now select REJECT to process rejection. Normally the work item would get completed here, but the
system will generate a POP-UP to prompt for the Reason.
This pop-up will appear due to our configuration. We enter the REJECTION Reason text and press OK

(Please note, if you cancel this POP-UP, the work item will still remain in your inbox and not get
completed. This is because we marked the Reason as MANDATORY)
Looking at the workflow log, we can see that the element _ATTACH_OBJECTS (Attachments) contains
the SOFM entry

Now looking at the e-mail step in the log, we will check the task description to see if our text is captured

You can see the Rejection Reason is captured. We can see this in the container also

Now running the SOST transaction to see if the same appears in the e-mail body as well


So we have successfully captured the REJECTION REASON TEXT and displayed it in the e-mail body.
You can use this functionality in multitude of other ways as per your business need in your project.

Process a User Decision Programmatically at Background
By Anirban Bhattacharjee, KPIT Cummins and Infosystems
Purpose: This document will show how to process a branch in a User Decision step in workflow via an
ABAP Program running at the background. The desired branch can be executed programmatically
without the approver having to process the work item from the SAP Inbox (SBWP or UWL).
Business Scenario: There are some business requirements where a user decision step needs to be
processed at the background. For example, if we need to process auto rejection when a user decision is
not executed within a stipulated time, we can employ this technique. We can also create an ABAP
Program by which an approver can also process mass approval / rejection of all user decision work items.
So this technique can come pretty handy on different business requirements.
Process: The process to set this up is pretty simple.
We simply need to call a function module and pass the work item ID of the User Decision along
with the decision branch.
We will discuss in details on how to achieve this functionality.
For our demo, I will consider two user decision work items that are sitting in a users business workplace.
We will process APPROVE for one and REJECT branch for the other without executing them from
business workplace (SBWP) or UWL in portal.
The two work items in the business work place of the user are shown below

We now look each the user decision step in workflow

Thus the APPROVE will correspond to branch 0001 and REJECT will correspond to 0002. If the step had
other decision options, they would get numbered as 0003, 0004 and so on.
Now to process the user decision via an ABAP program without executing the work item from SBWP or
Portal UWL we need to run the following function module
SAP_WAPI_DECISION_COMPLETE
Let us see what importing data this function module needs

Here in the parameter WORKITEM_ID we will pass the work item ID of the User Decision Step.
For USER, the default is SY-UNAME. Hence if this function module is called in an ABAP Program and
that program is executed at the background, it will pass the background system user ID.
The parameter DECISION_KEY decides which branch has to be processed in the User Decision Step. As
explained before, we will pass 0001 for APPROVE and 0002 for REJECT.
This will differ from case-to-case and scenario-to-scenario.
Now fetching the work item IDs of the above two user decision work items from their workflow logs
Work Item ID is 2733503 (We will process APPROVE for this)

Work Item ID is 2733501 (We will process REJECT for this)

Running the function module with work item ID 2733503 (Process Decision Key 0001 for APPROVE)


Click here to continue..

Process a User Decision Programmatically at Background
...Previous
Now we will look at the workflow graphical log to verify which branch was executed. In this case it should
be APPROVE (0001)

Result Outcome is APPROVE

So the APPROVE branch was executed here.
Now will run the function module with the other work item ID 2733501 (Process Decision Key 0002 for
REJECT)


Now we will look at the workflow graphical log to verify which branch was executed. In this case it should
be REJECT (0002)

Result outcome is REJECT

So the REJECT branch was executed here.
Now we will check the business work place via SBWP. The work items should have been removed.
BEFORE

AFTER

We can thus call this function module SAP_WAPI_DECISION_COMPLETE in our ABAP Program and
design it for so many different purposes.
We can also call the ABAP Program at the background and process work items accordingly.
Conclusion: We have thus successfully processed a user decision step programmatically without
executing the work item from the business workplace.

Forward a work item to your own currently logged in SAP ID
By Anirban Bhattacharjee, KPIT Cummins and Infosystems
Purpose: The purpose of this document is to demonstrate how you can forward a work item to your own
ID. This is not possible via the standard transaction SWIA. For example, if your SAP ID is XYZZ and
you are logged into SAP via this ID, you would try to forward the work item to this same ID by running
SWIA. This transaction you are executing from this ID itself. But SWIA will give you the prompt You
cannot choose yourself as an agent and not allow this forward.

Business Scenario: Many times when testing various workflow developments, we need to forward a
work item to our own ID for testing purposes. Sometimes it becomes difficult to maintain our own ID in the
Agent / Approver tables as they might need Customizing Transport Requests or other business
constraints. Standard T-Code SWIA does not allow forwarding the work items to your own ID. On such
situations we either need to forward the work item to some other test IDs or ask someone else to do it for
us.
Not any more, as with this technique you can even forward any work item to yourself while you
are logged in via that same SAP ID and be able to do your testing.
Process: The steps are very simple
We will take a work item and first try to forward it to the current logged in SAP ID (self ID) via T-Code
SWIA. This will not work.
We will then use a special function module to forward this work item to our own logged in SAP ID.
Looking at a work item in the workflow log
Here the following foreground work item currently does not have any agents assigned to it.

We check the work item ID from the technical log

The work item ID for the user decision step is 2733499. We will now run transaction SWIA and enter this
work item ID

Now we will select this row and try to forward it to the logged in ID via which this workflow is been tested
and this transaction is being executed


SWIA gives the following prompt when I try to forward the work item to the current logged in ID via which
SWIA is being executed and workflow being tested

The transaction SWIA prompts; You cannot choose yourself as an agent and does not allow
the Administrator Forward.
Click here to continue..

Forward a work item to your own currently logged in SAP ID
...Previous
Process to forward this work item to self:
Now to make this possible, we need to run the function module:
SWW_WI_FORWARD
This highly useful function module allows you to skip any previous checks and forward to any desired
Agent / Approver, including self.
We need to enter the same work item ID for the user decision step 2733499. This we had entered
previously in SWIA.
Pass the importing parameter PRECONDITIONS_CHECKED as X. This will ensure no conditions are
checked!!!
In the TABLES parameter NEW_AGENTS, pass your own logged in SAP ID, like US-XXYYZZ.
This should be the same agent to whom you tried to forward via SWIA but it failed. So this will be the self
logged in ID.
The function module screen will look as shown


Now execute the function module. We will see the function module returns the work item status as
READY with the selected new agent

To verify that the WI forward worked as expected, we look at the workflow log agents again

We can see now that the log does not say No selected agents, but is showing our own ID to which we
forwarded the work item to.
Also note the e-mail like icon, indicates that the work item came as a forward.
In technical log, the step details also confirms that the Forward was a success

Checking in business work place SBWP, to verify with certainty that the work item did get forwarded
successfully to own logged in ID

Conclusion: Thus we have successfully forwarded a dialog / foreground work item to own logged in ID
even when standard transaction SWIA did not allow the administrator forward to self.

Simplified Business Workplace -> Workflow Inbox in SAP R/3
By Anirban Bhattacharjee, KPIT Cummins and Infosystems
Purpose: The purpose of this document is to demonstrate how to display a simple view of the Business
Workplace (SBWP) which can be used in Custom Developments / Module Pool Screens or even Custom
Workflow Reports.
Business Scenario: The Business Workplace or SAP Workflow Inbox (as many people call it) can be
accessed via the transaction SBWP. It contains complete details of the Inbox, Outbox, E-Mail
Notifications, etc. But on many occasions the Business Users request for a simple view of this Business
Workplace. Something that will show just the workflow work items and omit the other details. That way;
the user can processes their desired work item only and not worry about other technicalities.
There is no need to custom develop this solution, since SAP has given us a very simple way to do it.
Process: The process involves running a couple of standard transaction codes. I will explain this in
details below.
Normal process of accessing the Business Workplace
We run the transaction SBWP to access the Business Workplace or click on the button as shown below

The Business Workflow screen looks like shown below

As you can see the SBWP is pretty detailed. The user can display a lot of information related to
Documents, Workflow Work Items, Started and Processing Workflows, Resubmission Entries, and many
more. The end user rarely uses all these. They are mainly bothered to see the work items that they have
to process.
In SBWP the work items to be processed are accessed as shown beloe:

The user can thus select the desired item to process. Similar process is followed for other entries where
the user needs to navigate in the tree and locate the desired item to process.
Simplified way of seeing the Business Workplace or SAP Inbox
Now we will simplify this view. For this we will run the first T-Code called SWLD_INPLACE1
SWLD_INPLACE1 - Embedded Inbox with a View
The entry screen of the T-Code looks as shown below

(Please note you can even filter tasks whose work items you do not want to be shown. Hence you can
create variants for this program and create custom transactions.
Based on business need, those transactions can be given to the end users.)
We can change the Title to something of our need and display just the INBOX section of SBWP as of now

The report shows a very simple ALV output of just the INBOX of SBWP and nothing else.

The user can process the desired work item from here and because of a simple view; it becomes a much
easier task.
Similarly we can display the OUTBOX also.


Click here to continue..

Simplified Business Workplace -> Workflow Inbox in SAP R/3
...Previous
The program thus shows us the workflow overview items of workflows that were processed via this user
ID.
Now we will run the second T-Code SWLD_INPLACE2
SWLD_INPLACE2 - Embedded Inbox with 2 Views
The entry screen of this transaction is shown below. We enter our own Custom Title and select INBOX for
the first part and OUTBOX for the second.

The output of this program is again a simple ALV.
This time the screen has two container elements. One displays the INBOX and the other OUTBOX (as
per selection criteria)

The first transaction SWLD_INPLACE1 calls the ABAP Report RSWL_INPLACE_INBOX_DEMO and the
second transactionSWLD_INPLACE2 calls the ABAP Report RSWL_INPLACE_INBOX_DEMO_PROFI.
You can copy these programs into custom programs and modify them as needed.
The tool bar allows the user to switch between views, just display the work item without executing and
many other features.
Display Work Item

Forward the work item

Manage Attachments in the work item

Other Functions

The workflow environment

Switch between INBOX, OUTBOX and RESUBMISSION views

Thus this program empowers the user with a lot of features while keeping everything simple.
I would suggest you to do a lot of study and research on the classes used in this program that is used to
first fetch the SBWP Details and then passing it to the ALV.
You can create your own custom screens and push buttons and provide a much simple Business
Workplace to the Client / End Users.
Business simply loves this simple view of the business workplace as it makes their work simple.
The major advantages of this process are:
Very simple layout and view. Very easy to use.
Custom program can be developed very easily and tweaked as per business need.
Advantageous to end users who need a simpler business workplace with lesser navigations,
buttons and menus.
Can be included in Module Pool Program screens.
Can be called from Custom Reports.
Selective task filtering and feature suppression possible by creating variants and assigning them to
different users as per need.
Conclusion: We were able to regenerate the different views of SBWP (Inbox and Outbox) via a simple
transaction. These views were much simple and easy to use compared to the standard Business
Workplace (SBWP).

Program Exits in Work Item for Workflow
By Anirban Bhattacharjee, KPIT Cummins and Infosystems
Purpose: The purpose of this document is to demonstrate how to use Program Exits in a Work Item for
Workflow.
Business Scenario: Many times we have scenarios where we want to do some additional custom
processing when a work item is created or executed.
SAP has given us a way by which we can design Program Exits in a work item. The events on which we
can program this are mentioned below
Before Work Item Creation
After Work Item Creation
Before Work Item Execution
After Work Item Execution
After the execution of a Synchronous Object Method in the work item
Before Physical Deletion of the Work Item
On the Status Change of a Work Item
On a Rule execution in the Work Item
After an action execution in the Work Item
Before and action execution in the Work Item
We will see that the class we will model later on in this tutorial will contain the methods that can be
implemented for handling the above events.
Here we will send e-mail via this Program Exit once when a work item is created and once when it
is executed.
There will be no e-mail steps modeled in the workflow. They will happen solely from the program exit.
Process to design the Program Exit in a Work Item
Let us look at the tab in a work item where this exit is designed

Note that the SAP Documentation states that the class that will be modeled here must support
theIF_SWF_IFS_WORKITEM_EXIT interface. Please ensure that inside this class we will not be using
any ABAP Instruction that can release the current LUW like COMMIT WORK, ROLLBACK WORK or
using RFC Function Calls.
Now we will design a class via the transaction SE24. We will call this class ZZCL_WORK_ITEM_EXIT.
The Properties tab of the class will look as shown. We will add the type group SWRCO

We will now declare the interface IF_SWF_IFS_WORKITEM_EXIT in the interface tab

Once we declare the interface, the attributes related to this interface will appear in the Attributes Tab.

Notice the events that can happen with a work item in the Description column. This is what was
mentioned at the start of the tutorial.
We will now add a couple of custom attributes as mentioned below:
WI_CONTEXT as a type reference to IF_WAPI_WORKITEM_CONTEXT; this interface returns the
various attributes of a work item.
Displaying this interface via SE24 and showing you the methods

To see how to implement these methods in a class, please
refer CL_SWF_RUN_WORKITEM_CONTEXT.
This class is very helpful to understand how to do various operations on a work item.
The other custom attribute will be named PROCESS_STATUS. This will contain a default
valuesap.bc.bmt.wfm.process.status.
The attributes tab now looks like as shown below

Both the attributes are Instance Attribute and Private visibility.
Now let us navigate to the Methods Tab of this class.

The only method created by default is EVENT_RAISED. This will be called whenever the Work Item
Events (mentioned at the start of the tutorial) are triggered.
The parameters that appear in this method are

(Note that there is a parameter IM_WORKITEM_CONTEXT which refers
interface IF_WAPI_WORKITEM_CONTEXT)
Now we will create two more methods called AFTER_WI_CREATION and AFTER_WI_EXECUTION as
shown.

Both the methods are Instance Method with Private Visibility.
Click here to continue..

Program Exits in Work Item for Workflow
...Previous
Write the following code in the AFTER_WI_CREATION method
(This code will send an e-mail to a dummy e-mail ID with the Work Item ID stating that it
was Created. Will trigger after work item is created)
METHOD after_wi_creation.

DATA: lcl_v_wi_id TYPE sww_wiid, "Work Item ID
lv_wid_text TYPE char12,
send_request TYPE REF TO cl_bcs,
text TYPE bcsy_text,
body_text TYPE so_text255,
document TYPE REF TO cl_document_bcs,
sender TYPE REF TO cl_sapuser_bcs,
recipient TYPE REF TO if_recipient_bcs,
bcs_exception TYPE REF TO cx_bcs,
sent_to_all TYPE os_boolean.

* For simplicity of the demo, we are only fetching the work item ID
* You can get the complete work item and workflow details as well
* Please refer class CL_SWF_RUN_WORKITEM_CONTEXT and interface IF_WAPI_WORKITEM_CON
TEXT
* Get the Work Item ID
CALL METHOD wi_context->get_workitem_id
RECEIVING
re_workitem = lcl_v_wi_id.

* Pass WID to text field
CLEAR: lv_wid_text.
lv_wid_text = lcl_v_wi_id.

*---------------------------------------------------------------------------------------- *
* Send an e-mail to a dummy e-mail ID stating that the above Work Item has been created
*----------------------------------------------------------------------------------------*
TRY.
* -------- create persistent send request ------------------------
send_request = cl_bcs=>create_persistent( ).

* -------- create and set document -------------------------------
* Build the e-mail Body
CLEAR: body_text.
CONCATENATE 'Work Item CREATED. WID:'
lv_wid_text INTO body_text SEPARATED BY space.

APPEND body_text TO text.
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = text
i_length = '12'
i_subject = 'E-Mail sent AFTER Work Item CREATION' ).

* Add document to send request
CALL METHOD send_request->set_document( document ).

* --------- set sender -------------------------------------------
* note: this is necessary only if you want to set the sender
* different from actual user (SY-UNAME). Otherwise sender is
* set automatically with actual user.

sender = cl_sapuser_bcs=>create( sy-uname ).
CALL METHOD send_request->set_sender
EXPORTING
i_sender = sender.

* --------- Add recipient (e-mail address) -----------------------
* Create recipient - passing a dummy e-mail ID here
recipient = cl_cam_address_bcs=>create_internet_address('anirban@testtest.com' ).

* Add recipient with its respective attributes to send request
CALL METHOD send_request->add_recipient
EXPORTING
i_recipient = recipient
i_express = 'X'.

* ---------- Send document ---------------------------------------
CALL METHOD send_request->send(
EXPORTING
i_with_error_screen = 'X'
RECEIVING
result = sent_to_all ).

COMMIT WORK.

* -----------------------------------------------------------
* * exception handling
* -----------------------------------------------------------
CATCH cx_bcs INTO bcs_exception.
* Write own code to catch exception
ENDTRY.

ENDMETHOD.
Write the following code in the AFTER_WI_EXECUTION method
(This code will send an e-mail to a dummy e-mail ID with the Work Item ID stating that it
was Executed. Will trigger after work item is executed)
METHOD after_wi_creation.

DATA: lcl_v_wi_id TYPE sww_wiid, "Work Item ID
lv_wid_text TYPE char12,
send_request TYPE REF TO cl_bcs,
text TYPE bcsy_text,
body_text TYPE so_text255,
document TYPE REF TO cl_document_bcs,
sender TYPE REF TO cl_sapuser_bcs,
recipient TYPE REF TO if_recipient_bcs,
bcs_exception TYPE REF TO cx_bcs,
sent_to_all TYPE os_boolean.

* For simplicity of the demo, we are only fetching the work item ID
* You can get the complete work item and workflow details as well
* Please refer class CL_SWF_RUN_WORKITEM_CONTEXT and interface IF_WAPI_WORKITEM_CON
TEXT
* Get the Work Item ID
CALL METHOD wi_context->get_workitem_id
RECEIVING
re_workitem = lcl_v_wi_id.

* Pass WID to text field
CLEAR: lv_wid_text.
lv_wid_text = lcl_v_wi_id.

*---------------------------------------------------------------------------------------- *
* Send an e-mail to a dummy e-mail ID stating that the above Work Item has been created
*---------------------------------------------------------------------------------------- *
TRY.
* -------- create persistent send request ------------------------
send_request = cl_bcs=>create_persistent( ).

* -------- create and set document -------------------------------
* Build the e-mail Body
CLEAR: body_text.
CONCATENATE 'Work Item EXECUTED. WID:'
lv_wid_text INTO body_text SEPARATED BY space.

APPEND body_text TO text.
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = text
i_length = '12'
i_subject = 'E-Mail sent AFTER Work Item EXECUTION' ).

* Add document to send request
CALL METHOD send_request->set_document( document ).

* --------- set sender -------------------------------------------
* note: this is necessary only if you want to set the sender
* different from actual user (SY-UNAME). Otherwise sender is
* set automatically with actual user.

sender = cl_sapuser_bcs=>create( sy-uname ).
CALL METHOD send_request->set_sender
EXPORTING
i_sender = sender.

* --------- Add recipient (e-mail address) -----------------------
* Create recipient - passing a dummy e-mail ID here
recipient = cl_cam_address_bcs=>create_internet_address('anirban@testtest.com' ).

* Add recipient with its respective attributes to send request
CALL METHOD send_request->add_recipient
EXPORTING
i_recipient = recipient
i_express = 'X'.

* ---------- Send document ---------------------------------------
CALL METHOD send_request->send(
EXPORTING
i_with_error_screen = 'X'
RECEIVING
result = sent_to_all ).

COMMIT WORK.

* -----------------------------------------------------------
* * exception handling
* -----------------------------------------------------------
CATCH cx_bcs INTO bcs_exception.
* Write own code to catch exception
ENDTRY.

ENDMETHOD.
Write the following code in the method EVENT_RAISED. In this method based on the Work Item event
triggered, our corresponding custom method will be called.
METHOD if_swf_ifs_workitem_exit~event_raised.

* Get the Work Item Context
me->wi_context = im_workitem_context.

* Check if the Event after WI Creation is triggered
IF im_event_name = swrco_event_after_creation.

* Call our method AFTER_WI_CREATION
me->after_wi_creation( ).

* Check if the Event after WI Execution is triggered
ELSEIF im_event_name = swrco_event_after_execution.

* Call our method AFTER_WI_EXECUTION
me->after_wi_execution( ).

ENDIF.

ENDMETHOD.

Click here to continue..

Program Exits in Work Item for Workflow
...Previous
Now save and activate the complete class ZZCL_WORK_ITEM_EXIT along with all its components.

Now we will call this class in our user decision step in the workflow at the tab Program Exits as shown
below

Now we save and activate the complete workflow definition as well.
Notice that there are no e-mail steps after the user decision anywhere in the workflow definition.

Now we will test the workflow via SWUS transaction. When the user decision step is created, the first e-
mail should go.

The work item ID is 412083 as seen below

Checking in SOST transaction if the Work Item Creation E-Mail has triggered


So we have successfully sent the first e-mail to the dummy e-mail ID, which went After Work Item
Creation via the program exit.
Notice the work item ID is 412083. This is correct as per workflow logs.
Now we will execute the work item. After execution, we will see the workflow log
BEFORE EXECUTION

AFTER EXECUTION

Checking SOST if the e-mail after WI execution has triggered


So we have successfully sent the second e-mail to the dummy e-mail ID, which went After Work Item
Execution via the program exit.
Conclusion: Hence we have successfully modeled the Program Exit that can be used in a work item.
With the help of this exit, we can do numerous custom operations at various events, which occur during
the complete life span of a work item.

Consistency and Extended Checks for Workflow Template and Tasks
By Anirban Bhattacharjee, KPIT Cummins and Infosystems
Purpose: The purpose of this document is to demonstrate how to perform Extended
Checks and Consistency Checks for aWorkflow Template and Standard Tasks.
Use and need: These checks are similar to extended checks and code inspector checks that are
performed on any ABAP Code, Function Module or Class.
Process: SAP has provided standard transactions to execute these checks. We will discuss these
transactions in detail.
These transactions are SWU7 and SWU4.
Transaction SWU7 is used for checking Workflow Templates.
The entry screen of SWU7 looks as shown. We enter the Workflow Template ID of the workflow which we
want to check

Execute the program. The output is as shown

We can see the program prompts in this case that there is one INFORMATION message: No start events
or start transactions/forms.
We can run this program with another workflow template that has more steps and see the following output

We can thus see that the program analyses each step of the workflow and displays the results.
The program also displays multiple check results at the same time. Simply enter the range of workflow
template IDs at the select option in selection screen.
This will give the following output

We can thus correct and tune the workflow to make its performance much better.
Transaction SWU4 is used for checking Standard Tasks.
The entry screen of SWU4 looks as shown. We enter the Standard Task ID of the Task which we want to
check

The output of the program is shown below

We can see that the program returned the Standard Task to be completely consistent. It would have
captured and displayed any errors / warnings / information accordingly.
Advantages of these transactions:
All possible runtime errors are displayed, like loss of data in bindings, data type mismatch, etc.
Containers elements that have been declared and not used are also displayed.
Event linkage and trigger failures are detected and displayed. Hence we can analyze event issues
without executing the workflow or displaying it.
Incomplete steps created in the workflow template are also captured.
Missing bindings in workflow and standard task are displayed.
Inconsistent code / bindings / containers, etc are detected.
Multiple Tasks and Workflow Templates can be checked at the same time.
These transactions perform many more extended checks which you will get to know when you run them
for different workflow templates and standard tasks that you might have created in the system. These
transactions are very important to analyze with certainty that the workflows will have a stable runtime
environment.
Conclusion: We have demonstrated successfully the standard transactions provided by SAP to perform
Consistency and Extended checks on Workflow Templates and Standard Tasks.

How to Trigger Class based workflow
By Rakesh Dhudipala
Scenario:
This explains a simple scenario to trigger Class based Workflow from program.
Step by Step procedure:
Go to SE24 transaction and create a class with ZCL_WEBDYNPRO_WF.

Go to Interfaces tab and implement the interface IF_WORKFLOW

Go events tab and create a event trigger with parameter i_kunnr.

Go to methods tab and and implement the SET_CUTOMER method with I_KUNNR as importing
parameter.

Set_customer method write the below code.
method set_customer.

* Data Declarations
DATA: lv_class TYPE sibftypeid,
lv_event TYPE sibfevent,
lv_objkey TYPE sibfinstid,
lr_event_parameters TYPE REF TO if_swf_ifs_parameter_container,
lv_param_name TYPE swfdname,
lv_id TYPE char10.


lv_class = 'ZCL_WEBDYNPRO_WF'.
lv_event = 'TRIGGER'.

* Instantiate an empty event container
CALL METHOD cl_swf_evt_event=>get_event_container
EXPORTING
im_objcateg = cl_swf_evt_event=>mc_objcateg_cl
im_objtype = lv_class
im_event = lv_event
RECEIVING
re_reference = lr_event_parameters.

* Set up the name/value pair to be added to the container
lv_param_name = 'I_KUNNR'. " parameter name of the event
lv_id = i_kunnr.


TRY.
CALL METHOD lr_event_parameters->set
EXPORTING
name = lv_param_name
value = lv_id.

CATCH cx_swf_cnt_cont_access_denied .
CATCH cx_swf_cnt_elem_access_denied .
CATCH cx_swf_cnt_elem_not_found .
CATCH cx_swf_cnt_elem_type_conflict .
CATCH cx_swf_cnt_unit_type_conflict .
CATCH cx_swf_cnt_elem_def_invalid .
CATCH cx_swf_cnt_container .
ENDTRY.

* Raise the event passing the event container
TRY.
CALL METHOD cl_swf_evt_event=>raise
EXPORTING
im_objcateg = cl_swf_evt_event=>mc_objcateg_cl
im_objtype = lv_class
im_event = lv_event
im_objkey = lv_objkey
im_event_container = lr_event_parameters.
CATCH cx_swf_evt_invalid_objtype .
CATCH cx_swf_evt_invalid_event .
ENDTRY.

COMMIT WORK.

endmethod.
Go to SWDD transaction and create a new workflow called ZTEST_WF

Go to header and Start events tab and enter the below details

Now if we call the SET_CUSTOMER method it will trigger the ZTEST_WF workflow.

Offline Workflow Approval in ECC R/3 without SAP Logon from E-Mail
(Outlook)
By Anirban Bhattacharjee, KPIT Cummins and Infosystems
Purpose: This document will demonstrate how you can set up a DEMO that will allow a user to
APPROVE or REJECT (Process as per requirement) a workflow work item directly from Outlook E-Mail
without logging into SAP. The approver does not need to have SAP GUI Installed in the system from
where the approval is being carried out. The approver also does not need to enter the SAP user ID and
password. These approval links are not SAP Shortcut links as generated by the RSWUWFML2 program
that is normally used for approval from outlook. These are normal MAILTO links and works on almost all
e-mail environments and internet browsers. This will also work on hand held devices like iPhone or
Blackberry if adequately configured with Exchange Server. Since the MAILTO links will work on the
Web Mail version of outlook as well, so normal browsers running on the handheld devices can also assist
in carrying out the Workflow Processing Offline.
Hence using this concept, you can now process work items, run ABAP programs, do any SAP activity
Offline remotely, without having to log into SAP.
Business Requirement: Business needs a way by which they can process workflow work items
completely offline. They want to be able to do this even when they are not in the SAP Network. The user
will not enter the SAP User ID and password, nor will they have SAP GUI in the system from where the
approval is being carried out. They should be able to directly process from Outlook which should work
across different browsers and handheld devices that run internet browsers.
How the DEMO Will Work, its features and ADVANTAGES
The various working steps, features and advantages of this demo are mentioned below
The workflow template consisting of a single user decision step with a work item exit will generate a
HTML Notification E-Mail to the Approver who also has received the User Decision Work Item for
processing.
This HTML E-Mail will demonstrate the data in Tabular Format and provide two links to the approver;
APPROVE and REJECT.
These links are typical MAILTO links. On clicking either of these links, the system will generate an auto
e-mail to send to the SAP System.
This e-mail will have the TO field auto-populated with the Offline System SAP ID and the Subject also
auto-populated with the action (A or R, for APPROVE or REJECT) and the Work Item ID of the User
Decision step that was sent to the approver.
The Inbound Exit Class will read this e-mail subject and process the work item.
User will not have to enter the SAP User ID or Password to send this auto email.
The user thus does not need to log on to the SAP System.
The user need not be in the SAP Network or VPN to send this email.
The user does not need to have SAP GUI present, since these links are not SAP Short Cut Links that
need SAP GUI.
Any application that can process MAILTO links can send these auto e-mails. Hence this works even in
handheld devices like iPhone, Blackberry, etc.
This works in various Internet Browsers. I have tested this in various versions of Microsoft Internet
Explorer, Google Chrome, etc.
Works on both Web Mail version of Microsoft Outlook and Normal Outlook
No need to schedule any batch job for programs like RSWUWFML2.
Highly customizable and easy to implement.
No third party tool required.
Using this concept you can run any SAP Transaction, schedule batch jobs, get report summary and
output in your e-mail from a remote system without logging into the SAP Network.
Inbound E-Mail Receiving configurations in SAP
We need to first create a user ID in Outlook along with a sub-domain that will point to the desired SAP
System. So for example if your company domain is www.yourdomain.com then the sub-domain would
be something like ecc-dev.yourdomain.com (This will be created by your Network and Infrastructure
People). You should be able to ping this domain.
Now let us name the Offline System User as ECCOFFLINE and then after a user is created in Microsoft
Outlook with above sub-domain, the e-mail ID will be eccoffline@ecc-dev.yourdomain.com. Please
note that this is a very critical step in this development and hence needs to be configured correctly. This
e-mail ID and sub-domain choice is completely your own. You can plan your own ID as per your choice.
This is the only configuration outside SAP on the Network / Exchange Server Side.
Create Offline User in SAP (SU01)
To receive e-mail in SAP, you need to first create a System User ID that will receive these e-mails. This
will be a system user with SYSTEM as the User Group. The user ID created is named ECCOFFLINE.
The Logon Data tab is shown below

This user must have three mandatory Profiles: S_A.SCON, SAP_ALL and SAP_NEW as shown below

The e-mail ID created in the first step, is also entered here in the Address tab as shown
(eccoffline@ecc-dev.yourdomain.com)

Configure the SAP-Connect node via SICF Transaction
The entry screen of SICF Transaction, press F8

Select the SAP-Connect Node and click the DISPLAY-CHANGE button as shown

Then activate the node as shown

After activation, the node screen will look as shown below

In the LOGON Data Tab, mention the ECCOFFLINE user and set the password

Click here to continue..

Offline Workflow Approval in ECC R/3 without SAP Logon from E-Mail
(Outlook)
...Previous
Configure and activate the SMTP Service via SMICM transaction
Run transaction SMICM or Report RSMONICM_STANDARD

Display the services via SHIFT+F1 or menu path as shown

This displays the Services as shown. Mention the SMTP port (normally 25, your Basis consultant will
provide you the port number, this is similar to the port settings done in SCOT transaction for SAP
Connect Outbound E-Mail Configuration) and activate the service. The GREEN check will indicate the
service is active. The Host Name will also be provided by your Basis / Security Consultant. This Host is
also similar to the host maintained in SCOT for the SMTP node

Activate and change the service via the menu as shown below

Configure and set the Inbound E-Mail Exit Configuration
Transaction SO50 is used to mention the inbound e-mail exit. This also can be access via SCOT
transaction by the menu path SettingsInbound Processing. This also calls SO50.
You can also run Report BCS_IBND_MAINT to call SO50 Transaction.

We have to write an Inbound Exit Class that will process the Inbound E-Mails. That class should be
mentioned here. (We will see later how to create this class)

Note that we mention our offline e-mail ID here (eccoffline@ecc-dev.yourdomain.com). The
class ZZZCL_PROCESS_INBOUND_WORKFLOW is the Exit Class designed to process inbound e-
mails as per our need. By default generally the first entry with the CL_APPOINTMENT_REPLY is always
present. We include our entry here and set the call sequence. The Document Class / Type is set as * to
allow all types of documents available in ECC.
Creation of the Inbound Exit Class
This class implements the interface IF_INBOUND_EXIT_BCS (BCS: Exit for Inbound Processing). The
properties tab of the class is shown

The Interfaces Tab

The Methods Tab

The CREATE_INSTANCE method is called by standard SAP (via SO50 Configuration) to create a unique
instance for each inbound e-mail. The code is written below
METHOD if_inbound_exit_bcs~create_instance.
DATA: ref TYPE REF TO zzzcl_process_inbound_workflow.
* Check if the Instance is initial
IF ref IS INITIAL.
CREATE OBJECT ref.
ENDIF.
* Return the Instance
ro_ref = ref.
ENDMETHOD.
The interface of the method CREATE_INSTANCE is shown

The PROCESS_INBOUND method is the place where we write the exit logic. This is where we will
process the desired work item of the workflow and process it based on the e-mail action / reply created by
the automated e-mail. The interface of method PROCESS_INBOUND is shown

The code in PROCESS_INBOUND method
METHOD if_inbound_exit_bcs~process_inbound.
* Declare for Inbound E-Mail processing (ENJOY :) :) )
DATA: lo_document TYPE REF TO if_document_bcs,
l_mail_attr TYPE bcss_dbpa,
l_mail_content TYPE bcss_dbpc,
lo_reply TYPE REF TO cl_send_request_bcs,
sender TYPE REF TO if_sender_bcs,
sender_addr TYPE string,
lv_email TYPE comm_id_long,
send_request TYPE REF TO cl_bcs,
ltext TYPE bcsy_text,
body_text TYPE so_text255,
document TYPE REF TO cl_document_bcs,
ex_sender TYPE REF TO cl_sapuser_bcs,
recipient TYPE REF TO if_recipient_bcs,
bcs_exception TYPE REF TO cx_bcs,
sent_to_all TYPE os_boolean,
lv_action TYPE char01,
lv_wid TYPE char12,
lv_wid_num TYPE sww_wiid,
lv_wid_func TYPE swr_struct-workitemid,
ls_swwwihead TYPE swwwihead,
lv_new_status TYPE sww_wistat,
lv_action_text TYPE char12.
*--------------------------------------------------------------------*
*- Get a pointer to the reply email object -*
*--------------------------------------------------------------------*
TRY.
lo_reply = io_sreq->reply( ).
CATCH cx_send_req_bcs.
ENDTRY.
**** Check to make sure this is from an approved Sender
sender = io_sreq->get_sender( ).
sender_addr = sender->address_string( ).
lv_email = sender_addr.
TRANSLATE sender_addr TO UPPER CASE.
**** Only reply if this message came from within our mail system or domain
**** SPAMMERS Beware, your e-mails will not be processed!!!
IF sender_addr CS '@YOURDOMAIN.COM'.
**** send reply and inbound processing
*--------------------------------------------------------------------*
*- Get email subject -*
*--------------------------------------------------------------------*
TRY.
lo_document = io_sreq->get_document( ).
l_mail_attr = lo_document->get_body_part_attributes( '1' ).
CATCH cx_document_bcs.
ENDTRY.
*--------------------------------------------------------------------*
*- Get mail body, here you can read the REJECTION Reason -*
*--------------------------------------------------------------------*
TRY.
l_mail_content = lo_document->get_body_part_content( '1' ).
CATCH cx_document_bcs.
ENDTRY.
*--------------------------------------------------------------------*
* YAAAAAHHHHHHOOOO at this point I have the Subject and the Body
*--------------------------------------------------------------------*
* Now read the subject and process the work item
* Condense the subject to remove blank spaces
CONDENSE l_mail_attr-subject.
* Read the action
lv_action = l_mail_attr-subject+0(1).
* Read the work item ID
lv_wid = l_mail_attr-subject+1(12).
* Pass to variables
lv_wid_num = lv_wid.
lv_wid_func = lv_wid_num.
* First check the status of the work item, process only if READY or IN-
PROCESS
SELECT SINGLE *
FROM swwwihead
INTO ls_swwwihead
WHERE wi_id = lv_wid_num.
* If data not found, indicates an invalid e-mail sent to offline ID
IF sy-subrc NE 0.
lv_wid = 'INVALID WID'.
ENDIF.
* Check the status, if COMPLETED, send the notification
IF ls_swwwihead-wi_stat = 'COMPLETED'.
TRY.
* -------- create persistent send request ------------------------
send_request = cl_bcs=>create_persistent( ).
* -------- create and set document -------------------------------
* Build the e-mail Body
CLEAR: body_text.
CONCATENATE 'WORK ITEM ID : '
lv_wid
'is in status "COMPLETED"' INTO body_text SEPARATED BY
space.
APPEND body_text TO ltext.
CLEAR: body_text.
CONCATENATE 'This has already been processed '
'and cannot be processed again.' INTO body_text
SEPARATED BY space.
APPEND body_text TO ltext.
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = ltext
i_length = '510'
i_subject = 'Work Item has already been
processed' ).
* Add document to send request
CALL METHOD send_request->set_document( document ).
* --------- set sender -------------------------------------------
* note: this is necessary only if you want to set the sender
* different from actual user (SY-UNAME). Otherwise sender is
* set automatically with actual user.
sender = cl_sapuser_bcs=>create( 'ECCOFFLINE' ).
CALL METHOD send_request->set_sender
EXPORTING
i_sender = sender.
* --------- Add recipient (e-mail address) -----------------------
* Create recipient - passing the receipient e-mail ID
recipient = cl_cam_address_bcs=>create_internet_address( lv_email
).
* Add recipient with its respective attributes to send request
CALL METHOD send_request->add_recipient
EXPORTING
i_recipient = recipient
i_express = 'X'.
* ---------- Send document ---------------------------------------
CALL METHOD send_request->send(
EXPORTING
i_with_error_screen = 'X'
RECEIVING
result = sent_to_all ).
COMMIT WORK.
CATCH cx_bcs INTO bcs_exception.
ENDTRY.
ELSEIF ls_swwwihead-wi_stat = 'READY' OR
ls_swwwihead-wi_stat = 'STARTED'.
* First process the Work Item Based on the action
IF lv_action = 'A'.
* Set the ACTION Text
lv_action_text = 'APPROVED'.
* If APPROVED
CALL FUNCTION 'SAP_WAPI_DECISION_COMPLETE'
EXPORTING
workitem_id = lv_wid_func
language = sy-langu
user = sy-uname
decision_key = '0001' "Approval Node
do_commit = 'X'
IMPORTING
new_status = lv_new_status
* TABLES
* MESSAGE_LINES =
* MESSAGE_STRUCT =
.
ELSEIF lv_action = 'R'.
* Set the ACTION Text
lv_action_text = 'REJECTED'.
* If REJECTED
CALL FUNCTION 'SAP_WAPI_DECISION_COMPLETE'
EXPORTING
workitem_id = lv_wid_func
language = sy-langu
user = sy-uname
decision_key = '0002' "Rejection Node
do_commit = 'X'
IMPORTING
new_status = lv_new_status
* TABLES
* MESSAGE_LINES =
* MESSAGE_STRUCT =
.
ENDIF.
* After the action now send the e-mail
TRY.
* -------- create persistent send request ------------------------
send_request = cl_bcs=>create_persistent( ).
* -------- create and set document -------------------------------
* Build the e-mail Body
CLEAR: body_text.
CONCATENATE 'WORK ITEM ID : '
lv_wid
'has been'
lv_action_text INTO body_text SEPARATED BY space.
APPEND body_text TO ltext.
CLEAR: body_text.
CONCATENATE 'New status of work item is '
lv_new_status INTO body_text SEPARATED BY space.
APPEND body_text TO ltext.
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = ltext
i_length = '510'
i_subject = 'Work Item processing
confirmation' ).
* Add document to send request
CALL METHOD send_request->set_document( document ).
* --------- set sender -------------------------------------------
* note: this is necessary only if you want to set the sender
* different from actual user (SY-UNAME). Otherwise sender is
* set automatically with actual user.
sender = cl_sapuser_bcs=>create( 'ECCOFFLINE' ).
CALL METHOD send_request->set_sender
EXPORTING
i_sender = sender.
* --------- Add recipient (e-mail address) -----------------------
* Create recipient - passing the receipient e-mail ID
recipient = cl_cam_address_bcs=>create_internet_address( lv_email
).
* Add recipient with its respective attributes to send request
CALL METHOD send_request->add_recipient
EXPORTING
i_recipient = recipient
i_express = 'X'.
* ---------- Send document ---------------------------------------
CALL METHOD send_request->send(
EXPORTING
i_with_error_screen = 'X'
RECEIVING
result = sent_to_all ).
COMMIT WORK.
CATCH cx_bcs INTO bcs_exception.
ENDTRY.
ELSE.
* This means the work item is in ERROR or some exception status, NOTIFY!!!!!
* Here you can reply back to the user if they send invalid e-mails to
ECCOFFLINE other then clicking on the Processing Links
TRY.
* -------- create persistent send request ------------------------
send_request = cl_bcs=>create_persistent( ).
* -------- create and set document -------------------------------
* Build the e-mail Body based on the Work Item ID
IF lv_wid = 'INVALID WID'.
* Build E-Mail for Invalid WID
CLEAR: body_text.
CONCATENATE 'This system e-mail is meant only for OFFLINE
WORKFLOW Processing.'
'Please do not send any e-mails to this ID other then
via Workflow Processing Offline Links.' INTO body_text SEPARATED BY space.
APPEND body_text TO ltext.
CLEAR: body_text.
CONCATENATE 'This is a system generated auto e-mail '
'Please do not reply to this ID.' INTO body_text
SEPARATED BY space.
APPEND body_text TO ltext.
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = ltext
i_length = '510'
i_subject = 'System ID - Please do not
reply or send E-Mail' ).
ELSE.
* Build E-Mail body for Valid WID gone in exception status
CLEAR: body_text.
CONCATENATE 'WORK ITEM ID '
lv_wid
'might not have processed as desired.' INTO body_text
SEPARATED BY space.
APPEND body_text TO ltext.
CLEAR: body_text.
CONCATENATE 'Please forward this e-mail to the '
'System / Workflow Administrator to help you and
analyze / solve it.' INTO body_text SEPARATED BY space.
APPEND body_text TO ltext.
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = ltext
i_length = '510'
i_subject = 'Work Item exception might have
occured' ).
ENDIF.
* Add document to send request
CALL METHOD send_request->set_document( document ).
* --------- set sender -------------------------------------------
* note: this is necessary only if you want to set the sender
* different from actual user (SY-UNAME). Otherwise sender is
* set automatically with actual user.
sender = cl_sapuser_bcs=>create( 'ECCOFFLINE' ).
CALL METHOD send_request->set_sender
EXPORTING
i_sender = sender.
* --------- Add recipient (e-mail address) -----------------------
* Create recipient - passing the receipient e-mail ID
recipient = cl_cam_address_bcs=>create_internet_address( lv_email
).
* Add recipient with its respective attributes to send request
CALL METHOD send_request->add_recipient
EXPORTING
i_recipient = recipient
i_express = 'X'.
* ---------- Send document ---------------------------------------
CALL METHOD send_request->send(
EXPORTING
i_with_error_screen = 'X'
RECEIVING
result = sent_to_all ).
COMMIT WORK.
CATCH cx_bcs INTO bcs_exception.
ENDTRY.
ENDIF.
* End the IF for checking valid E-Mail
ENDIF.
ENDMETHOD.
Click here to continue..

Offline Workflow Approval in ECC R/3 without SAP Logon from E-Mail
(Outlook)
...Previous
Creation of the workflow template
I will not discuss in details on this step. The SAP Technical site has a huge number of tutorials that will
show you how to do this. For our demo, we are creating a very simple workflow template with a single
User Decision Step. The template is shown (Notice there is no SEND MAIL step. E-Mail is sent via the
Work Item exit)


The work item exit is mentioned in the user decision step as shown

To know how to create a work item exit, please follow this LINK in SAP Technical to learn and follow the
steps in the tutorial.
(If that does not open copy and paste this link in your
browserhttp://saptechnical.com/Tutorials/Workflow/Exit/Index.htm)
In the exit, we write our e-mail logic in the method AFTER_WI_CREATION. This method is triggered the
moment the User Decision Work Item is created and sent to the approver. Our e-mail is also created and
sent almost at the same instant. The code in this method is shown. The system e-mail ID will depend on
the ID created by your infrastructure team.
(Note: I have shown two different ways to send the e-mail; one via the BCS Class and the other the
SOFM Function Module. Please select whichever way you prefer. Remember to comment out one of the
ways, else you will get two e-mails on Work Item Creation )
Code for method AFTER_WI_CREATION
METHOD after_wi_creation.
DATA: lcl_v_wi_id TYPE sww_wiid, "Work Item ID
lv_wid_read TYPE sww_wiid, "Work Item ID to read container
data
lv_wid_text TYPE char12,
l_it_father_wis TYPE STANDARD TABLE OF swwwihead,
l_wa_father_wis TYPE swwwihead,
send_request TYPE REF TO cl_bcs,
text TYPE bcsy_text,
body_text TYPE so_text255,
document TYPE REF TO cl_document_bcs,
sender TYPE REF TO cl_sapuser_bcs,
recipient TYPE REF TO if_recipient_bcs,
bcs_exception TYPE REF TO cx_bcs,
sent_to_all TYPE os_boolean.
* Declare the Work Item Container data
DATA: l_it_wi_container TYPE STANDARD TABLE OF swcont,
l_wa_wi_container TYPE swcont,
l_wa_wi_header TYPE swwwihead.
* Declaration for the Dynamic Values in text
DATA: lv_belnr TYPE belnr_d,
lv_bukrs TYPE bukrs,
lv_gjahr TYPE char04,
lv_email TYPE comm_id_long,
lv_lines TYPE i,
lv_so_obj_len TYPE so_obj_len.
* Other e-mail technique to do the declarations
DATA : it_message TYPE STANDARD TABLE OF solisti1,
wa_message TYPE solisti1,
it_attach TYPE STANDARD TABLE OF solisti1,
wa_attach TYPE solisti1,
t_receivers TYPE STANDARD TABLE OF somlreci1,
wa_receivers TYPE somlreci1,
w_doc_data TYPE sodocchgi1.
* For simplicity of the demo, we are only fetching the work item ID
* You can get the complete work item and workflow details as well
* Please refer class CL_SWF_RUN_WORKITEM_CONTEXT and interface
IF_WAPI_WORKITEM_CONTEXT
* Get the Work Item ID
CALL METHOD wi_context->get_workitem_id
RECEIVING
re_workitem = lcl_v_wi_id.
* Pass WID to text field to concatenate to the e-mail body for MAILTO link
CLEAR: lv_wid_text.
lv_wid_text = lcl_v_wi_id.
* Fetch the parent work item ID
REFRESH: l_it_father_wis[].
CALL FUNCTION 'SWW_WI_FIND_FATHER_WIS'
EXPORTING
wi_id = lcl_v_wi_id
TABLES
father_wis = l_it_father_wis.
* Read the Father WID, if not found then running WID is Father WID
CLEAR: l_wa_father_wis, lv_wid_read.
READ TABLE l_it_father_wis INTO l_wa_father_wis INDEX 1.
* If Father Work Item ID found pass to the WID Variable else pass the
Original WID
IF sy-subrc = 0.
lv_wid_read = l_wa_father_wis-wi_id.
ELSE.
lv_wid_read = lcl_v_wi_id.
ENDIF.
* Read the work flow container data with WID Populated
REFRESH: l_it_wi_container[].
CLEAR: l_wa_wi_header.
lv_wid_read = lcl_v_wi_id - 1.
CALL FUNCTION 'SWW_WI_CONTAINER_READ'
EXPORTING
wi_id = lv_wid_read
TABLES
wi_container = l_it_wi_container
CHANGING
wi_header = l_wa_wi_header
EXCEPTIONS
container_does_not_exist = 1
read_failed = 2
OTHERS = 3.
* If the call is a success
IF sy-subrc = 0.
CLEAR: lv_belnr, lv_bukrs, lv_gjahr, lv_email.
* Read the container values and pass them to generate the dynamic e-mail body
* Read the Company Code from Workflow WS91000120
CLEAR: l_wa_wi_container.
READ TABLE l_it_wi_container INTO l_wa_wi_container
WITH KEY element = 'BUKRS'.
IF sy-subrc = 0.
CONDENSE l_wa_wi_container-value.
lv_bukrs = l_wa_wi_container-value.
ENDIF.
* Read the Invoice Number from Workflow WS91000120
CLEAR: l_wa_wi_container.
READ TABLE l_it_wi_container INTO l_wa_wi_container
WITH KEY element = 'BELNR'.
IF sy-subrc = 0.
CONDENSE l_wa_wi_container-value.
lv_belnr = l_wa_wi_container-value.
ENDIF.
* Read the Fiscal Year from Workflow WS91000120
CLEAR: l_wa_wi_container.
READ TABLE l_it_wi_container INTO l_wa_wi_container
WITH KEY element = 'GJAHR'.
IF sy-subrc = 0.
CONDENSE l_wa_wi_container-value.
lv_gjahr = l_wa_wi_container-value.
ENDIF.
* Read the Company Code from Workflow WS91000120
CLEAR: l_wa_wi_container.
READ TABLE l_it_wi_container INTO l_wa_wi_container
WITH KEY element = 'EMAIL_ID'.
IF sy-subrc = 0.
CONDENSE l_wa_wi_container-value.
lv_email = l_wa_wi_container-value.
ENDIF.
ENDIF.
*----------------------------------------------------------------------------
------------*
* Send an e-mail to a dummy e-mail ID stating that the above Work Item has
been created
*----------------------------------------------------------------------------
------------*
TRY.
* -------- create persistent send request ------------------------
send_request = cl_bcs=>create_persistent( ).
* -------- create and set document -------------------------------
* Build the e-mail Body
* CLEAR: body_text.
* CONCATENATE 'Work Item Created. WID:'
* lv_wid_text INTO body_text SEPARATED BY space.
*--------------------------------------------------------------------*
* Start the Mail Body
*--------------------------------------------------------------------*
CLEAR: body_text, wa_message.
CONCATENATE body_text
'<html><body>Dear User'
INTO body_text.
APPEND body_text TO text.
wa_message-line = body_text.
APPEND wa_message TO it_message.
CLEAR: wa_message.
CLEAR: body_text.
CONCATENATE body_text
'<h3>What you need to know:</h3>'
INTO body_text.
APPEND body_text TO text.
wa_message-line = body_text.
APPEND wa_message TO it_message.
CLEAR: wa_message.
CLEAR: body_text.
CONCATENATE body_text
'Below is the invoice waiting for your approval.'
INTO body_text.
APPEND body_text TO text.
wa_message-line = body_text.
APPEND wa_message TO it_message.
CLEAR: wa_message.
CLEAR: body_text.
CONCATENATE body_text
'<h4>Invoice Information</h4>'
INTO body_text.
APPEND body_text TO text.
wa_message-line = body_text.
APPEND wa_message TO it_message.
CLEAR: wa_message.
*--------------------------------------------------------------------*
* Start Invoice Information in Table
*--------------------------------------------------------------------*
CLEAR: body_text.
CONCATENATE body_text
'<table border = "1" bgcolor = "skyblue">'
INTO body_text.
APPEND body_text TO text.
wa_message-line = body_text.
APPEND wa_message TO it_message.
CLEAR: wa_message.
CLEAR: body_text.
CONCATENATE body_text
'<tr><td>Invoice Number</td><td>'
lv_belnr
'</td></tr>'
INTO body_text.
CONDENSE body_text.
APPEND body_text TO text.
wa_message-line = body_text.
APPEND wa_message TO it_message.
CLEAR: wa_message.
CLEAR: body_text.
CONCATENATE body_text
'<tr><td>Company Code</td><td>'
lv_bukrs
'</td></tr>'
INTO body_text.
CONDENSE body_text.
APPEND body_text TO text.
wa_message-line = body_text.
APPEND wa_message TO it_message.
CLEAR: wa_message.
CLEAR: body_text.
CONCATENATE body_text
'<tr><td>Fiscal Year</td><td>'
lv_gjahr
'</td></tr>'
INTO body_text.
CONDENSE body_text.
APPEND body_text TO text.
wa_message-line = body_text.
APPEND wa_message TO it_message.
CLEAR: wa_message.
CLEAR: body_text.
CONCATENATE body_text
'<tr><td>Gross Invoice Value
(USD)</td><td>200,000.00</td></tr></table>'
INTO body_text.
APPEND body_text TO text.
wa_message-line = body_text.
APPEND wa_message TO it_message.
CLEAR: wa_message.
*--------------------------------------------------------------------*
* End Invoice Table
*--------------------------------------------------------------------*
*--------------------------------------------------------------------*
* Start Multiline Table
*--------------------------------------------------------------------*
CLEAR: body_text.
CONCATENATE body_text
'<h4>Line Item Data displayed in tabular format</h4>'
INTO body_text.
APPEND body_text TO text.
wa_message-line = body_text.
APPEND wa_message TO it_message.
CLEAR: wa_message.
CLEAR: body_text.
CONCATENATE body_text
'<table border="1" bgcolor = "lightgreen">'
INTO body_text.
APPEND body_text TO text.
wa_message-line = body_text.
APPEND wa_message TO it_message.
CLEAR: wa_message.
CLEAR: body_text.
CONCATENATE body_text
'<tr>'
'<th>Header 1</th>'
'<th>Header 2</th>'
'<th>Header 3</th>'
'<th>Header 4</th>'
'<tr>'
'<td>row 1, cell 1</td>'
'<td>row 1, cell 2</td>'
'<td>row 1, cell 3</td>'
'<td>row 1, cell 4</td>'
'</tr>'
INTO body_text.
APPEND body_text TO text.
wa_message-line = body_text.
APPEND wa_message TO it_message.
CLEAR: wa_message.
CLEAR: body_text.
CONCATENATE body_text
'<tr>'
'<td>row 2, cell 1</td>'
'<td>row 2, cell 2</td>'
'<td>row 2, cell 3</td>'
'<td>row 2, cell 4</td>'
'</tr>'
INTO body_text.
APPEND body_text TO text.
wa_message-line = body_text.
APPEND wa_message TO it_message.
CLEAR: wa_message.
CLEAR: body_text.
CONCATENATE body_text
'<tr>'
'<td>row 3, cell 1</td>'
'<td>row 3, cell 2</td>'
'<td>row 3, cell 3</td>'
'<td>row 3, cell 4</td>'
'</tr>'
INTO body_text.
APPEND body_text TO text.
wa_message-line = body_text.
APPEND wa_message TO it_message.
CLEAR: wa_message.
CLEAR: body_text.
CONCATENATE body_text
'<tr>'
'<td>row 4, cell 1</td>'
'<td>row 4, cell 2</td>'
'<td>row 4, cell 3</td>'
'<td>row 4, cell 4</td>'
'</tr>'
'</table>'
INTO body_text.
APPEND body_text TO text.
wa_message-line = body_text.
APPEND wa_message TO it_message.
CLEAR: wa_message.
*--------------------------------------------------------------------*
* End Multiline Table
*--------------------------------------------------------------------*
CLEAR: body_text.
CONCATENATE body_text
'<h3>What you need to do:</h3>'
INTO body_text.
APPEND body_text TO text.
wa_message-line = body_text.
APPEND wa_message TO it_message.
CLEAR: wa_message.
CLEAR: body_text.
CONCATENATE body_text
'To approve the invoice via portal, please log onto the
YOUR-COMPANY Business Portal by clicking here:'
INTO body_text.
APPEND body_text TO text.
wa_message-line = body_text.
APPEND wa_message TO it_message.
CLEAR: wa_message.
* Generate the YOUR Company Portal Production Link
CLEAR: body_text.
CONCATENATE body_text
'<a
href="http://companyprderp.yourcompany.net:50000/irj/portal">YOUR_COMPANY
Portal</a></p>'
INTO body_text.
APPEND body_text TO text.
wa_message-line = body_text.
APPEND wa_message TO it_message.
CLEAR: wa_message.
* Genrate the Dynamic MAILTO Links
CLEAR: body_text.
CONCATENATE body_text
'To process directly from e-mail, make your selection here
&nbsp;'
INTO body_text.
APPEND body_text TO text.
wa_message-line = body_text.
APPEND wa_message TO it_message.
CLEAR: wa_message.
CLEAR: body_text.
CONCATENATE body_text
'<a href="mailto:eccoffline@ecc-
dev.yourcompany.com?subject=A'
lv_wid_text
' - Approve Document">APPROVE</a>&nbsp;&nbsp;'
INTO body_text.
APPEND body_text TO text.
wa_message-line = body_text.
APPEND wa_message TO it_message.
CLEAR: wa_message.
CLEAR: body_text.
CONCATENATE body_text
'<a href="mailto:eccoffline@ecc-
dev.yourcompany.com?subject=R'
lv_wid_text
' - Reject Document">REJECT</a>'
INTO body_text.
APPEND body_text TO text.
wa_message-line = body_text.
APPEND wa_message TO it_message.
CLEAR: wa_message.
* Start DISCLAIMERS and WARNING Notifications
CLEAR: body_text.
CONCATENATE body_text
'<br><h4>Please Note: The links will send an e-mail via
MICROSOFT OUTLOOK.'
'Please do not change the subject, body or any information
in that e-mail.</h4>'
INTO body_text.
APPEND body_text TO text.
wa_message-line = body_text.
APPEND wa_message TO it_message.
CLEAR: wa_message.
CLEAR: body_text.
CONCATENATE body_text
'<h4>MICROSOFT Outlook must be installed in your
system.</h4>'
INTO body_text.
APPEND body_text TO text.
wa_message-line = body_text.
APPEND wa_message TO it_message.
CLEAR: wa_message.
CLEAR: body_text.
CONCATENATE body_text
'<span style="color:#FF0000">' "This is color for RED.
Browser Safe colors mandatory to prevent broswer crash.
INTO body_text.
APPEND body_text TO text.
wa_message-line = body_text.
APPEND wa_message TO it_message.
CLEAR: wa_message.
CLEAR: body_text.
CONCATENATE body_text
'<h4> <style="color: red"> CAUTION! Please do not reply to
this e-mail.'
'For approval via e-mail, please click the links provided
only. </h4></br>'
INTO body_text.
APPEND body_text TO text.
wa_message-line = body_text.
APPEND wa_message TO it_message.
CLEAR: wa_message.
CLEAR: body_text.
CONCATENATE body_text
'</span>'
INTO body_text.
APPEND body_text TO text.
wa_message-line = body_text.
APPEND wa_message TO it_message.
CLEAR: wa_message.
CLEAR: body_text.
CONCATENATE body_text
'</body></html>'
INTO body_text.
APPEND body_text TO text.
wa_message-line = body_text.
APPEND wa_message TO it_message.
CLEAR: wa_message.
*--------------------------------------------------------------------*
* End of HTML Code Body
*--------------------------------------------------------------------*
* Calculate the Document Size
CLEAR: lv_lines, lv_so_obj_len.
DESCRIBE TABLE it_message LINES lv_lines.
lv_so_obj_len = 255 * lv_lines.
* Create the Document
document = cl_document_bcs=>create_document(
i_type = 'HTM' "Send HTML E-Mail and not 'RAW'
i_text = text
i_length = lv_so_obj_len
i_subject = 'E-Mail sent AFTER Work Item Creation' ).
* Add document to send request
CALL METHOD send_request->set_document( document ).
* --------- set sender -------------------------------------------
* note: this is necessary only if you want to set the sender
* different from actual user (SY-UNAME). Otherwise sender is
* set automatically with actual user.
sender = cl_sapuser_bcs=>create( sy-uname ).
CALL METHOD send_request->set_sender
EXPORTING
i_sender = sender.
* --------- Add recipient (e-mail address) -----------------------
* Create recipient - passing the e-mail ID here
recipient = cl_cam_address_bcs=>create_internet_address( lv_email ).
* Add recipient with its respective attributes to send request
CALL METHOD send_request->add_recipient
EXPORTING
i_recipient = recipient
i_express = 'X'.
* ---------- Send document ---------------------------------------
CALL METHOD send_request->send(
EXPORTING
i_with_error_screen = 'X'
RECEIVING
result = sent_to_all ).
* IF sent_to_all = 'X'.
* WRITE text-003.
* ENDIF.
COMMIT WORK.
* -----------------------------------------------------------
* * exception handling
* -----------------------------------------------------------
CATCH cx_bcs INTO bcs_exception.
* WRITE: text-001.
* WRITE: text-002, bcs_exception->error_type.
* EXIT.
ENDTRY.
*--------------------------------------------------------------------*
* Another way to send e-mail in HTML via function module
*--------------------------------------------------------------------*
CLEAR: w_doc_data.
w_doc_data-sensitivty = 'F'. "Fill the document data and get size of
attachment
w_doc_data-doc_size = lv_lines * 255. "Populate the subject/generic
message attributes
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = 'E-Mail sent AFTER Work Item Creation'.
CLEAR: wa_receivers.
REFRESH: t_receivers[].
wa_receivers-receiver = lv_email. "Get requestor mail id from table
PA0105 based on his PERNR.
wa_receivers-rec_type = 'U'.
wa_receivers-com_type = 'INT'.
wa_receivers-notif_del = 'X'.
wa_receivers-notif_ndel = 'X'.
APPEND wa_receivers TO t_receivers.
* Send the HTML E-Mail
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
EXPORTING
document_data = w_doc_data
document_type = 'HTM' " To get the notification in HTML format
commit_work = 'X'
TABLES
object_content = it_message
receivers = t_receivers.
ENDMETHOD.
This completes our coding and configuration for our demo. We will now test our demo and see how it
works.
Testing of the Offline Approval Demo
Running transaction SWUS to test the workflow with following parameters

The work flow is triggered with work item ID 2735147 (Parent / Father Work Item)

The workflow log shown

Now running SOST, we see the e-mail is triggered via the work item exit (there is no SEND MAIL step in
our workflow)

We push this e-mail from SOST (Not needed if SCOT Batch Job is set up)

Message exits from SAP Connect

Now checking in OUTLOOK Inbox, e-mail received at 08-FEB-2013; 3:41 PM

The APPROVAL and REJECTION links in the e-mail will look as shown

We click on APPROVE as of now, the following auto e-mail is generated. Notice that the TO field is auto
populated with the ECC-OFFLINE approval ID.
The subject is a concatenation of the Processing Action (A = Approve) and the Work Item ID

Click here to continue..

Offline Workflow Approval in ECC R/3 without SAP Logon from E-Mail
(Outlook)
...Previous
I am now clicking on SEND. I am not changing the SUBJECT or TO Field in this e-mail. This is crucial. I
can see the e-mail is in the SENT ITEMS in OUTLOOK Web-Mail

Now I am running the transaction SOIN for Inbound Send Requests (SMTP). This can also be substituted
by Report RSBCSIN

I can see the e-mail has been received at SAP . If you can see this, that your Inbound E-mail
Configuration is correct. You have crossed a big hurdle here.

Display the trace of this e-mail (Note: I have activated TRACE in SCOT, this is mandatory to know what
has happened in system)
The trace can be displayed from the SOIN screen. Notice the toolbar in that screen shot, the trace button
is shown

The trace screen opens as shown below (If trace is not active in SCOT, this screen will show no
entries)

Now the moment the e-mail was received by the system, our Inbound Exit should have triggered and
processed the work item.
We can verify this from the trace. If we double click on the trace entry, it will show us all the details, our
exit was instantiated and triggered as shown in the highlighted entries below. Also we can see that the
RETURN Code was 0 which indicates that the method PROCESS_INBOUND was called correctly

So now we will check in SOST. We should see a reply from the Workflow System that the work item has
been approved. This was processed in the methodPROCESS_INBOUND coded in the Inbound Exit
Class ZZZCL_PROCESS_INBOUND_WORKFLOW

This e-mail was triggered by the Inbound Exit Class (notifying the processing). Displaying the e-mail
body

Checking the workflow log, the work item should have been processed as APPROVED
BEFORE Status IN PROCESS

AFTER Status COMPLETED and action outcome is APPROVED

(Note the work item was not processed manually in Business Workplace SBWP, but was
processed in the Inbound Exit Class via function module SAP_WAPI_DECISION_COMPLETE.
Please study the code in method PROCESS_INBOUND in class
ZZZCL_PROCESS_INBOUND_WORKFLOW. So you can process any code, transaction, etc offline
via e-mail using this concept. Simply create specific SUBJECT line in the auto e-mail and model
your code on that)

Above work item is also removed from SBWP (Business Workplace)

Checking in OUTLOOK, we should have received the e-mail

Click here to continue..

Offline Workflow Approval in ECC R/3 without SAP Logon from E-Mail
(Outlook)
...Previous
The OUTLOOK E-mail as seen in outlook. So the effect is; the moment the approver clicked on
APPROVE link in the first Workflow Notification HTML e-mail, a few seconds later he receives a system
e-mail informing him of the action carried out and stating the success.

We open the e-mail to see the details and also to verify if the e-mail opens OK

Now what happens if the user clicks on APPROVE or REJECTED link on the approval e-mail again?
The work item will not be re-processed or processed multiple times. The system will receive the e-mail
and send a notification back to user that the work item was already processed.
(You can design your own system response and code to handle this case where the approver might click
on the links multiple times and send multiple e-mails to the system. The system will always process the
first e-mail it receives on a first-come-first-served basis)
Let us see how this works. User clicks on REJECT link on the System Notification e-mail. This process
the user does after he has already clicked on APPROVE and has sent the auto e-mail to the SAP
System. The concerned work item has already been processed as APPROVED so system cannot
process it again. Hence system should inform this to the user

On clicking REJECT, we get the below e-mail, notice that the work item ID is same as before of the
already approved item.

The e-mail is sent by Outlook and received by the SAP system as shown, highlighted in YELLOW

The e-mail BODY is shown below

Now the Inbound Exit will trigger again and find that this item is already processed, so system will send
back the notification e-mail. Notice that the system response is very fast. The system received the e-mail
at time 03:15:41 and sends the auto reply at 03:15:41 (see SOIN and SOST screen shot). This is
because in this case, it did not need to spend time to process the work item, which has already been
processed by the first e-mail

Displaying the body of the e-mail

Checking the e-mail in OUTLOOK

The e-mail is opened to check the contents and validate if it opens correctly

We have successfully processed a work item via e-mail without logging into SAP System. We also
managed to get the system respond to the e-mails and do the desired processing and reply back with the
correct status. We did not require SAP GUI to do any processing. Also SAP Login ID and Password was
not needed to do the Workflow Processing..

Passing multiline parameters from an ABAP Class event to a Workflow
container
By Rodrigo Arenas Arriola, Mexico
We usually trigger a Workflow by a Business Object event. However, what happen with an ABAP Class
event? Is it possible to pass a multiline parameter from the event to the Workflow container. Here you
have the answer.
First, we need to create an ABAP class for using it with workflows (you can review another tutorial from
this site to do it).
The name of our class is ZCL_TRIGGER_MULTILINE.

Constructor method has the import parameter IM_KEY (the key for the instantiation).

And also the class has the event TRIGGER with two parameters:
ENAME TYPE PA0001-ENAME
DESCRIPTION TYPE SWFTVALUE (TYPE TABLE OF swc_value)

Next, we need to create a Workflow template and use the ABAP class as its trigger. Notice that the
workflow has the same parameters as the event -ENAME and DESCRIPTION-.

Click here to continue...

Passing multiline parameters from an ABAP Class event to a Workflow
container
...Previous
Now, we need the ABAP code for raising the event (and for passing parameters).
REPORT ytrigger_multiline.

* Data Declarations
DATA g_evt_param_container TYPE REF TO if_swf_cnt_container.
DATA g_obj_category TYPE swfeclstyp VALUE 'CL'.

DATA it_description TYPE STANDARD TABLE OF swc_value.

DATA l_event_ref TYPE REF TO if_swf_evt_event.
DATA l_objtype TYPE sibftypeid VALUE 'ZCL_TRIGGER_MULTILINE'.
DATA l_event TYPE swo_event VALUE 'TRIGGER'.
DATA l_objkey TYPE swo_typeid.
DATA l_selected_handlers TYPE i.
DATA l_event_container TYPE REF TO if_swf_ifs_parameter_container.

DATA vl_returncode TYPE sysubrc.
DATA l_return TYPE swf_return.

DATA lex_root TYPE REF TO cx_root.
DATA l_string TYPE string.

***

PARAMETERS p_name TYPE pa0001-ename.

* Instantiate the specific container for the class event
TRY.
CALL METHOD cl_swf_evt_utilities=>get_specific_container
EXPORTING
im_objcateg = g_obj_category
im_objtype = l_objtype
im_event = l_event
RECEIVING
re_container = g_evt_param_container.
CATCH cx_swf_evt_exception.
ENDTRY.

* Aggregate single parameter to event container
TRY.
CALL METHOD g_evt_param_container->if_swf_ifs_parameter_container~set
EXPORTING
name = 'ENAME'
value = p_name
IMPORTING
returncode = vl_returncode.

CATCH cx_swf_cnt_cont_access_denied
cx_swf_cnt_elem_not_found
cx_swf_cnt_elem_access_denied
cx_swf_cnt_elem_type_conflict
cx_swf_cnt_unit_type_conflict
cx_swf_cnt_elem_def_invalid
cx_swf_cnt_invalid_qname
cx_swf_cnt_container.
ENDTRY.


* Aggregate multiline parameter to event container

APPEND 'This is a test with ABAP classes' TO it_description.
APPEND 'for passing a multiline parameter' TO it_description.
APPEND 'to a container of an event' TO it_description.
APPEND 'in order to execute a Workflow.' TO it_description.

TRY.
CALL METHOD g_evt_param_container->if_swf_ifs_parameter_container~set
EXPORTING
name = 'DESCRIPTION'
value = it_description
IMPORTING
returncode = vl_returncode.

CATCH cx_swf_cnt_cont_access_denied
cx_swf_cnt_elem_not_found
cx_swf_cnt_elem_access_denied
cx_swf_cnt_elem_type_conflict
cx_swf_cnt_unit_type_conflict
cx_swf_cnt_elem_def_invalid
cx_swf_cnt_invalid_qname
cx_swf_cnt_container.
ENDTRY.

*-----------------------------------------------------------------------
*- Check the Container, if all obligatory elements are filled
*-----------------------------------------------------------------------
IF g_evt_param_container IS BOUND.
TRY.
CALL METHOD g_evt_param_container->check
EXPORTING
check_oblig_parameters = 'X'
check_oblig_not_initial = 'X'.
CATCH cx_swf_cnt_elem_check_failed.

ENDTRY.
ENDIF.

*---- move the event-parameters (only if they exist)
IF g_evt_param_container IS BOUND.
IF g_evt_param_container->get_element_count( ) > 0.
l_event_container ?= g_evt_param_container.
ENDIF.
ENDIF.

l_objkey = '12345'.

*---- get a instance for the event
CALL METHOD cl_swf_evt_event=>get_instance
EXPORTING
im_objcateg = g_obj_category
im_objtype = l_objtype
im_event = l_event
im_objkey = l_objkey
im_event_container = l_event_container
RECEIVING
re_event = l_event_ref.

*-----------------------------------------------------------------------
* RAISE
*-----------------------------------------------------------------------
TRY.
* Refresh the buffers
cl_swf_evt_services=>reset_buffers( ).

* Trigger the event
CALL METHOD l_event_ref->raise.

CATCH cx_root INTO lex_root. " should never occur
IF lex_root IS BOUND.
l_string = lex_root->get_text( ).
MESSAGE l_string TYPE 'I'.
ENDIF.
ENDTRY.

COMMIT WORK.

Finally, we can test our code.

And then, we review the workflow log, and data within the workflow container looks like this.


Concept of Re-evaluate agents for active work items in SAP Workflow
By Srinivas Reddy Oota, HCL Technologies
In real world we may frequently experience a situation where in we have to wait for approval from our
manager and in some cases we may not get approval in time. In these cases from SAP perspective we
have options of escalating via email in the form of deadline monitoring or forwarding the same approval
request to someone else. In this blog I choose the concept of re-evaluate agents for an active work item
which will re-initiate the active work item once the dead line is reached. Below is a simple example, might
not be a real time scenario.
An employee will raise a travel request from a custom SAP screen. The travel request will go to his line
manager for approval. If the travel is on the same day of request raised, the approval work item will wait
one hour for line manager approval if not approved; the same work item will go to the platform manager
and the work item will disappear from line manager's inbox.
For demo purpose I have created a simple screen from where user will raise travel request. The custom
screen is linked to an event in a global class which will start workflow. Agent determination is done from a
functional method in the global class. Which will be called from a rule function module. Dead line
determination is also done from a functional method in the global class.
Note: My idea is only to explain the concept of re-evaluate agents for active work items with a simple
example. The below example might not be a real-time business scenario.
It is assumed that reader of the article has knowledge in the following areas:
Creating global classes.
Workflow triggering via class.
Workflow development.
Implementing LPOR methods.
Creating rules
ABAP dialog programming.
Development objects:
The development has a custom database table created in SE11 which will store approver id's.

Create a global class ZCL_WORKFLOW_DEMO in SE24 assign the interface
IF_WORKFLOW

Define the new structure and table Types in the types tab.

Declaration of types as shown below

Create the attributes in the attributes tab as shown below.

LPOR method implementation

FIND_BY_LPOR implementation

Create the below methods.

Signature of Constructor method

Code inside constructor method:

Signature of GET_APPROVER method

Logic inside GET_APPROVER method.
The method has a very simple logic, if the import parameter DEADLINE_FLAG is initial, line manager will
be returned else if the import parameter DEADLINE_FLAG is populated with 'X' platform manager will be
returned. This method will be called from the rule function module which is assigned in the user decision
step.

Signature of TRIGGER_WF method

Click here to continue..

Concept of Re-evaluate agents for active work items in SAP Workflow
...Previous
Logic of TRIGGER_WF method.
The method will populate the required parameters for event and start the workflow.
METHOD trigger_wf.
*Locals
DATA:lv_objkey TYPE sibfinstid,
lif_event_parameters TYPE REF TO if_swf_ifs_parameter_container,
lif_event TYPE REF TO if_swf_evt_event,
lcl_event TYPE REF TO cl_swf_evt_event,
lv_evt_id TYPE swe_evtid.
CONSTANTS: lc_event TYPE sibfevent VALUE 'START_WORKFLOW'.
*Get event container
CALL METHOD cl_swf_evt_event=>get_event_container
EXPORTING
im_objcateg = gv_catid
im_objtype = gv_typeid
im_event = lc_event
RECEIVING
re_reference = lif_event_parameters.
*Set elements
TRY.
CALL METHOD lif_event_parameters->set
EXPORTING
name = 'START_DATE'
value = im_start_date.
CATCH cx_swf_cnt_cont_access_denied .
CATCH cx_swf_cnt_elem_access_denied .
CATCH cx_swf_cnt_elem_not_found .
CATCH cx_swf_cnt_elem_type_conflict .
CATCH cx_swf_cnt_unit_type_conflict .
CATCH cx_swf_cnt_elem_def_invalid .
CATCH cx_swf_cnt_container .
ENDTRY.

TRY.
CALL METHOD lif_event_parameters->set
EXPORTING
name = 'START_TIME'
value = im_start_time.
CATCH cx_swf_cnt_cont_access_denied .
CATCH cx_swf_cnt_elem_access_denied .
CATCH cx_swf_cnt_elem_not_found .
CATCH cx_swf_cnt_elem_type_conflict .
CATCH cx_swf_cnt_unit_type_conflict .
CATCH cx_swf_cnt_elem_def_invalid .
CATCH cx_swf_cnt_container .
ENDTRY.


CALL METHOD cl_swf_evt_event=>get_instance
EXPORTING
im_objcateg = gv_catid
im_objtype = gv_typeid
im_event = lc_event
im_objkey = gv_user
im_event_container = lif_event_parameters
RECEIVING
re_event = lif_event.

TRY.
CALL METHOD lif_event->raise
.
CATCH cx_swf_evt_invalid_objtype .
CATCH cx_swf_evt_invalid_event .
ENDTRY.

COMMIT WORK.

lcl_event ?= lif_event.

CALL METHOD lcl_event->get_event_id
RECEIVING
re_event_id = ev_event_id.

ENDMETHOD.
Signature of GET_DEADLINE_DATE_TIME method

Logic of GET_DEADLINE_DATE_TIME method
Usually for determining dead line date, time we use factory calendar id, as my intension is only to show
the Re-evaluate agent's concept hence ignored the complex logic of determining dead line date and time.
I have hard coded the dead line time = start time + 1 hour.

Events of the ZCL_WORKFLOW_DEMO class

START_WORKFLOW event parameters

NEW_APPROVER event will be assigned towards Receiver type "Re-evaluate rules of active work
items". This event does not have any parameters.
Design a screen in SE80 as shown below and assign a t-code. ZTRAVEL.

Write the below code inside PAI module

Create a new workflow template in PFTC with the start event START_WORKFLOW of the business class
ZCL_WORKFLOW_DEMO. Assign start events as shown below.

Create the WF container elements compatible to the event parameters and bind and shown.

Create workflow container element WF_ZCL_WOKFLOW_DEMO selecting object type class and value
as ZCL_WOKFLOW_DEMO.

As the workflow container element WF_ZCL_WOKFLOW_DEMO need to be populated from Event
binding set the properties as Import as shown below.

Create workflow container element WF_START_DATE selecting SYST for structure and DATUM for field
as shown below.

Click here to continue

Concept of Re-evaluate agents for active work items in SAP Workflow
...Previous
As the workflow container element WF_START_DATE need to be populated from Event binding set the
properties as Import as shown below.

Create workflow container element WF_START_TIME selecting SYST for structure and UZEIT for field
as shown below.

As the workflow container element WF_START_TIME need to be populated from Event binding set the
properties as Import as shown below.

Create workflow container element WF_DEADLINE_REACHED with type FLAG as shown below.
Properties selection is not required for this parameter.

Click on the Version-Dependent (current workflow version) tab in the workflow template header. Click on
events tab and assign the NEW_APPROVER event towards Receiver type "Re-evaluate rules of active
work items" as shown below.

Click on details button, a new pop-up screen will appear and fill the fields as shown below.

Create a container step and call the functional method GET_DEADLINE_DATE_TIME to populate
WF_TIME. To call the functional method from expression write the below code
%ZCL_WORKFLOW_DEMO.GET_DEADLINE_DATE_TIME(IM_TIME=&WF_START_TIME&)%

Create a rule function module ZFM_APPROVER in SE37 and paste the code as shown below.

Create a rule in PFAC selecting function to be executed category

Click here to continue..

Concept of Re-evaluate agents for active work items in SAP Workflow
...Previous
Create the rule container elements as shown below.

IM_USER data type is SYST-UNAME
IM_DEADLINE_REACHED data type is FLAG.
Create a user decision step with APPROVE and REJECT buttons, select Rule for agents category and
assign the rule id created in the above step.

In the latest end tab select, select expression for Refer.date/time, modeled for ACTION and assign
WF_START_DATE for Date and WF_START_TIME for time fields. Provide a meaning full outcome
name. This will create a new branch for the user decision step.

Create a event creator step and pass the values as shown below. Once the process reach the event
creator step all the active work items will reset, active work items will disappear from the inboxes and will
be reprocessed.

Here ends all the development. The workflow definition looks as shown below.

Open the transaction ZTRAVEL pass the values as shown below pass date, time and click on SUBMIT.

After clicking on Submit button the function code assigned to the Submit button will trigger the event and
workflow will start. As per the logic a work item should go to the line manager's inbox.
Check your Line manager's inbox for the work item.
Note: Do not perform any action on the work item.

In the workflow log we can see the deadline time and date. Once the deadline time is reached the new
branch will start processing will populate the DEADLINE_FLAG with X in the first step and once the
second step is reached all the work items will be re-initiated and the existing active work item will
disappear.

Login into platform manager system. Go to SAP Inbox you will find the work item waiting.

Login to line manager system. Go to SAP Inbox. The work item will de disappeared.

Determination of Release Code of PO and PR
By Argadip Kar, IBM India
Workflow related to Change Purchase order:
The Workflow is triggered by the Event CHANGE of Business Object BUS2012. The Change Event does
not pass the Release Code with it. We have to determine the Release Code Virtually by adding an
Attribute or putting the Code in the Method.
There is no Standard Workflow for Changing of Purchase Order. This is very useful when there is a
requirement that approval is required for non-significant changes in Purchase Order.
Each Purchase Order can have at the most 8 Release codes. The Release Code is stored in table T16FS
and is determined using the field FRGGR (Release group) and FRGSX(Release Strategy). These two
fields are obtained from table EKKO (Purchase Order Header table). In this table we have to provide the
Purchase order number and we will get the field FRGGR (Release group) and FRGSX(Release
Strategy).
Now how to determine which Release Code needs to be released. The Release Code will be released
sequentially in table T16FS. In table T16FS, 8 Release codes can be stored for a particular combination
of Release group and Release Strategy. The field FRGZU (Release status) determines which Release
Codes needs to be released. If the Release Status field value is X and there are 3 Release Codes in
Table T16FS corresponding to the Release group and Release Strategy then the Release Code that
needs to be released is the value that is assigned to field FRGC2 in table T16FS. After the Release has
been done for Release code assigned to field FRGC2, we have to again pick the value of field FRGC3
and Release it.
Lets take an example of Purchase Order 4500017173. The Release group for this Purchase Order is ZR
and Release Strategy is GM. Initially the Release status is blank, as none of the Release Code has been
released.

Continued in the following screenshot:

Lets find out how many Release codes are there for the combination of Release group ZR and Release
Strategy GM. There are three Release Codes for this combination. They are PA,PM and GM
respectively.

Lets now try to release for Release Code PA.


After we have released the Purchase Order for Release Code PA the Release Status should be X in
table EKKO for this Purchase Order number. Let us check.

We should now try to Release the purchase order for Release Code PM by going to Transaction Code
ME29N.


After we have released the Purchase Order for Release Code PM the Release Status should be XX in
table EKKO for this Purchase Order number. Let us check.

Click here to continue...

Determination of Release Code of PO and PR
...Previous
We should now try to Release the purchase order for Release Code GM by going to Transaction Code
ME29N.


After we have released the Purchase Order for Release Code GM the Release Status should be XXX in
table EKKO for this Purchase Order number. Let us check.

Now if we want to reset the Release of this Purchase Order then we can reset the Release for any
Release Code and that would be reflected in the field Release Status of table EKKO for that Purchase
Order number we are dealing with.
Let us reset the Release for Release Code PM of purchase Order


After we have reset the Release for Purchase Order for Release Code PM the Release Status should be
X in table EKKO for this Purchase Order number. Let us check.

Now in Order to release the Purchase Order we have again follow the above method to find out the
Release Code in Table T16FS using the Release group and Release Strategy of that Purchase Order.
This method is very useful when a Purchase Order requires approval when its is Released for the
changes in the following fields of a Purchase order:
Material code
Short Text Description
Delivery Address
Account Assignment (Cost Centre/ WBS Element/ Internal Order)
Delivery Date
Tax Code
For changes in the above field the Event SIGNIFICANTLYCHANGED of Business Object Bus2012
does not gets triggered. So in order to filter the Changes we have to have Change Event of Business
Object BUS2012 as the Triggering event of the Workflow and we have to determine the Release code by
using the method mentioned above, as Change event does not pass the Release Code of the purchase
Order.

Purchase Order Release Strategy
By Gowri Shankar, HCL Technologies
This document describes step-by-step procedure for triggering workflow while creating a PO.
Depends on PO value, it selects the level of approver one or two level.
Step1:
First we need to set the PO Release strategy.
Go to transaction SPRO.

Step 2: Click SAP Reference IMG.

Step 3:
Choose Material management Purchasing Purchase order
Release Procedure for Purchase order Define release Procedure for Purchase Order.

Step 4: The following screen appears.

Step 5: First let us set the release group

Press save and come back.
Step 6: Now the screen looks like this.

Step 7: Now select the Release code.


Step 8: After Release Codes, now select Release indicator.

Click here to continue...

Purchase Order Release Strategy
...Previous
Step 9:
Next you need to set the release strategy.

On double-clicking the record, the following screen appears. Here you need to set the conditions.

Step 10 :
Finally you need to set the workflow strategy.

Save your entries.

Now the release procedure is configured.
1) Go to transaction SWDD and open the standard SAP workflow definition WS20000075.

2) To tailor the workflow definition as per our requirements, let us take a copy of the standard workflow
definition and modify the same.

3) After that give the name for standard workflow.




Click here to continue...

Purchase Order Release Strategy
...Previous
4) Now a copy of the standard workflow is available. We can modify this workflow definition as per the
client requirements.


5) Note the workflow definition id. Go to the transaction PFTC.

6) Select the task type as Workflow template.
And task as 99900281(workflow definition id). Next click the change button.

7) Select the tab Triggering events. (The alternative method for getting into this screen is by selecting
Basic data (Hat symbol on the application toolbar) in the workflow definition)

8) Select the step and select Call binding editor.

The Following screen appears. Do the check and activate it.

Step 9 :


Step 11 : Go back to the earlier screen and activate the event.

The event linkage is now activated.

Hereafter whenever a purchase order is created, the workflow is automatically triggered.

Configuration of Purchase Requisition Release Strategy
By Suresh Kumar Parvathaneni
Following is the procedure for workflow enabling of Purchase Requisition Release Strategy:
1. The standard workflow template provided by SAP for PR Release is WS00000038. This information
could be retrieved from the SAP help.
2. It is assumed that the release procedure has been setup in the system by the functional consultant,
as shown below:

3. The customization of the PR Release Strategy could be verified at the following location:
SPRO SAP Reference IMG Material Management Purchasing Purchase
Requisition Release Procedure Procedure with classification Setup procedure with
classification
4. Click on workflow in the above screen (screenshot shown below):

5. Now define the recipients of the PR Release work item as per the release group (refer to screenshot
below). For testing purposes, the recipient type is taken as US, instead this can also be taken as
Position, Organization Unit and others.

6. Now go back to the previous screen and click on Release Codes. Here enter the value 1 in the
workflow column for the release groups the workflow has to be configured.

7. Activate the event linkage of the workflow either in SWDD or PFTC.

8. Mark all the tasks (unless background tasks) as General Task in the agent assignment and
generate.

PO List Retrieval for which Workflow isn't triggered due to Event
Linkage deactivation
By Arghadip Kar, IBM India
Workflow Release Purchase Order (WS200000075).
Assume a scenario wherein the Linkage between the event and the workflow got de-activated due to
some accidental Customizing request released in Production. Now how to retrieve the PO numbers for
which the Workflow needs to be triggered manually. Remember the POs should all be subjected to
Release Strategy. We have to also keep in mind that the users might release the PO manually so we
need to remove those POs, which were released already. How to accomplish this without writing a single
piece of code?
We were using Standard Workflow WS20000075. The triggering event of this Workflow is
RELEASESTEPCREATED of BUS2012. This event gets triggered for New Pos that is subjected to
Release Strategy or for existing POs, which is subjected to New Release Strategy on changing the PO.
Let us retrieve the list of POs that are subjected to Release Strategy. Go to transaction Code SE16 and
provide the table name as EKKO (PO Header table)

Now check for the records with release strategy not equals to SPACE and release indicator as Blocked.


We should also give the creation Date during which this issue was faced.


These are the list of POs for which Workflow might have triggered and assigned to approver who has not
released it or for which Workflow has not been triggered.
We have a standard Transaction Code SWI6 to check the Workflow Overview individually but how to
check in a massive manner.


The above method is cumbersome and will take a lot of time. There is a table SWIWIOBJCT

Give the same key field as we gave in SWI6 transaction Code.


If it has any entries, it implies that Workflow has been triggered for it. This table can be utilized to check
Workflow for multiple key fields having same business object and is a very handy way to handle this crisis
situation.

Triggering of Events/Workflow upon Status Change
By Suresh Kumar Parvathaneni
Scenario: Triggering of events upon Status Change of a Production Order
Creation of Production Order: Before configuring workflow for Production Order, we would first create a
production order and observe the events that are triggered by SAP (by default).
Switch on the event trace using the transaction SWELS
Go to transaction CO01 and create a Production Order.


Press SAVE and click on the following button.

The Production order is created. Now go to either CO02/CO03 to understand the statuses set for the
document created.

Click on i button.

The above statuses are set to this document.
Switch of the event trace and check for the events triggered during the production order
creation.

Now the requirement is to trigger a custom event, when the status MANC is set (please refer to the
above screens for details).
Steps to trigger a custom event whenever the production order status is set to MANC:
Go to transaction SWO1.
Create a custom business object by taking BUS2005 (Production Order) as Super type.
Create a new event, for example MANC.

Implement and Release the business object component and the business object.
Go to transaction BSVW (Status Management)
Click on Customer Settings

Go to change mode and click on New Entries.
Enter the following:

Press SAVE and select the above row and click on Status restrictions.
Click on New entries
Press F4 and select MANC from the list.

Save the entries.
Now create a production order (Tcode CO01) and if the status of the document is MANC, then the above
event would be triggered.
Following is the screenshot from event trace:



Configuration of Quality Notification Workflow
By Suresh Kumar Parvathaneni
Following is the procedure to configure workflow for Quality Notifications:
Note: This document has prepared by taking screenshots from 4.6C system.
1. Activate the following linkages in the transactions SWETYPV:

The above screenshot is from the SAP 4.6C system.
2. Next, navigate to SPRO SAP Reference IMG Quality Management Quality
Notifications Notification Processing Activate Workflow Template.
3. Click on Activate event linkage. Here activate the event linkage for Quality Notification INFO
(Screenshot shown below):

4. Now go back and click on Assign agents to tasks. Here make the quality notification tasks as
General task as shown below:

The screen for the above in 4.7 system is as follows:

5. Now create a quality notification using the transaction QM01. The work item would reach the
coordinator (User) that is mentioned/specified during the notification creation.

Triggering a Workflow whenever a PO is changed
By Kanika Chopra, Infosys Technologies
This document details the procedure to trigger a Workflow whenever a PO is changed. To download the
document, please click here.
Arquivo PPT no diretrio

Configuration of Leave request workflow for ESS/MSS
By Suresh Kumar Parvathaneni, YASH Technologies
Scenario: Need to customize the SAP leave request workflow for ESS application.
Approach: Following are the activities that need to be performed to achieve the above requirement:
1. Workflow part
2. SPRO Configurations
3. Testing from R/3 side
Workflow Part:
Before you proceed with the leave application, ensure that the workflow settings are in place (Transaction
SWU3).
The standard workflow provided by SAP for the leave application is WS12300111. To customize this to
our requirement, it is recommended to take a copy of the workflow instead of modifying the standard one.
To copy the standard workflow, go to transaction PFTC.

Select the task type Workflow template and enter the workflow number in the task number. Click on
Copy task.
Following popup appears. Click on Copy task

Assign the object to the required package and the request.
Now open the custom workflow definition created above.

Now go to Basic data Agent assignment for task (see the screenshot below):

Select the task as General task

Now ensure that the agent assignment for all the steps in the workflow is as per your requirement. If not,
you can modify the same to meet your requirements. (Please take a copy of the standard tasks as well, if
they are to be modified).
Configuration Settings:
The configuration settings are to make the standard SAP leave application to trigger the custom workflow
application for the leave requests instead of standard workflow.
Please note that the configuration settings are covered only from a Workflow perspective and not
elaborative.
Go to transaction PTARQ.

Click here to continue...

Configuration of Leave request workflow for ESS/MSS
...Previous
Click on Customizing (this is a short route instead of going through SPRO).
Now navigate to Specify Processing Processes for Types of Leave as shown below:

Following popup appears. Click on Define Absences/Processing Processes

Now double-click the leave request types for which we need to trigger the custom workflow.

The following screen appears:

Now to have the workflow to process the leave request, check the check box as highlighted in the above
screenshot.
When the checkbox is highlighted, following fields appear:

Here enter the custom workflow we have created earlier.

Click on Save.
Testing:
To test the application, we need to create a leave request from the portal. Alternatively, we can use the
transaction PTARQ to create a leave application.
Click on Test Application in the transaction PTARQ.

Enter the Employee number (PERNR) and click on the tab Create Request

Enter the Infotype number 2001, the sub-type (leave type), Date and other information as required.

Save your leave request.
Tip: Please note that the work item generated by this workflow, for approving the leave request, cannot
be directly executed from the SAP inbox. SAP issues the following message when we try to execute the
work item from R/3 (Following is the only code in the method attached to the task):


For testing purpose, you can use the function module PT_ARQ_REQUEST_EXECUTE to approve the
leave request and to complete the work item.

IM_REQUEST_ID is the unique leave request identifier (Document ID).
Also read: "Tracking the Leave requests of an Employee with the status from Workflow"

Display Workflow overview of one object (Purchase Order) in another
(Purchase Requisition)
By Arghadip Kar, IBM
We have regularly a requirement to display the Workflow overview of a particular document for example
Purchase Requisition which is linked to the main document for which the Workflow is triggered. Here in
this case we can take an example of purchase Order as the main document. Lets first go to Transaction
Code PFTC and create a new Workflow.

Create Container element PO which refers to BUS2012.

Create container element PR in workflow.


In order to obtain the PR from the PO we have create a virtual attribute PR that calculates the PR linked
to a PO.

Lets us check the PR also

This is the PO on which we will do our testing. First check whether the PR is getting retrieved in the
Business object.

Now lets do the design on how to accomplish. There is a standard Business Object SYSTEM which has
a Method GENERICINSTANTIATE.

In this method if we pass the Object Key and Business Object name we get the Object Instance.

Click here to continue...

Display Workflow overview of one object (Purchase Order) in another
(Purchase Requisition)
...Previous
Lets put this in our Workflow development a task that executes the above method.

Here is the Task that we have created

Lets us make the binding.


Here is our design. Now we will test by going to SWUS transaction code.

We give the PO number and execute.

Here is the Workflow Log. We can check the Technical information.

The status is completed. Now let us check the Workflow Overview of PO from ME23n Transaction code.

Here is the workflow log in PO. But actual test is in the respective PR screen. Let us check.

Here is the result. The workflow Log of PO is getting showed in the PR it is linked to.

Trigger workflow when a record is created in a database table
By Swarna S, Tata Consultancy Services
This document shows step by step process for the creation of a business object, table maintenance
events and linking them to workflows in the SAP system.
Also this document shows how to integrate the business object created with SAP workflow.
Business objects are of two types
With Super Type
Without Super type
Business Object with Super type
In this case the BO refers to a standard BO already existing in the SAP system.
We create our own BO with by coping the existing standard BO .
Lets suppose we have a BO BUS2014 which is Purchase contract. Now if I want to add my own
attributes /methods in addition to the standard, I will create ZBUS2014 which has all the items in
BUS2014 plus my own attributes and methods. In this case BUS2014 is called Supertype of my
BO ZBUS2014.
Business Object without Super type
Here my BO is completely customized. It does not refer to any standard BO available in the SAP
system.
Now in the slides down we will see step by step approach to create a BO without a supertype.
Scenario
We have a Z table by the name ZEMPDETAIL. This table has three fields, Employee Number (PERNR),
start date(BEGDA) and end date(ENDDA).Whenever a record is entered in this table ,the start date
(BEGDA) should be saved as the sy-datum (current date) automatically and mail should be triggered
stating that a new entry has been created into the table to a particular user .
We will first see the creation of the table and its table maintenance step by step
1.) The table is created as per the below screenshot via SE11.

2.) The table maintenance is also created for the table in the same transaction

3.) Once the table maintenance is created, an event is linked to it.

4.) There are many events available for table maintenance and we will choose the event create new entry
to suit a purpose and write a code for the same

5.) Now we write a routine / code for that event.

6.) The code is to change the start date to sy-datum and create an event using the function module
SAP_WAPI_CREATE_EVENT. Once the event is created it is linked to workflow.

Now the table part is over. We will see the step by step approach to create a business object and the
linkage to a workflow.
Step 1 Creating a business object
Go to the Transaction SWO1.

Step 2 Create the object type by giving the details

Click here to continue...


Trigger workflow when a record is created in a database table
...Previous
Step 3 Business object without a super type is now created. Existence check and Display methods are
the default methods available in all sorts of Business objects. IFSAP is the standard interface used across
all the business objects. These get automatically appended to our business object as soon as we create
them.

Step 4 Creating an event in the Business object so that it can be linked to the table maintenance event
and called as workflow start event.

STEP 5 The business object has to be implemented. First the object components are implemented and
then the business object is implemented.


STEP 6 - The business object has to be released. First the object is released and then the business
object components are released.


STEP 9 Business Object Generation

The business object ZTAB_CHG is ready for and can be used in the workflow.
Step 1 -> Workflow builder SWDD

Step 2 - >Creating a start event for workflow to trigger

Step 3 -> Activate the start events

Step 4 -> Set the default
binding

Click here to continue...

Trigger workflow when a record is created in a database table
...Previous
Step 5 -> Agent Assignment


Step6 -> Event linkage is now available from our workflow definition side

Step 7 -> Inserting a step in our workflow for sending a mail

Step 8 -> Email step in a workflow
Here we enter the user id, the subject of the mail and the mail content as per the screenshot below.

Step 9 -> The workflow is now completed

Step 10 -> Now we have to notify the system whenever the event ZCHANGE_DATA occurs this workflow
should be called.
The Transaction code is SWETYPV

Step 11 -> Check for a duplicate entry for the same object BO type.

Step 12 -> Linking the workflow with event


OUTPUT
Output at the business workplace (Transaction SBWP) of user specified in the workflow:

And the mail content in the inbox of the user is shown in the screenshot below.


Triggering approval workflows only for Purchase Orders belonging to
a particular purchasing group (using startup conditions)
By Swarna S, Tata Consultancy Services
Triggering approval workflows only for Purchase Orders belonging to purchasing group 003 and
displaying the ME23N screen as a transaction to the approver
1.) Go to SWDD transaction and create a new workflow
2.) Go to the header of the workflow and give the start events

3.) Give the relevant Business object BUS2012 and the method RELEASESTEPCREATED in the start
events.
4.) Activate the starting conditions
5.) Give the binding (Event container to the workflow container)

6.) Give the start conditions for this workflow

7.) Create an activity step in the workflow

8.) Bind the workflow container to the activity step Display PO

9.) Task Display PO

10.) Workflow is complete

Click here to continue...

Triggering approval workflows only for Purchase Orders belonging to
a particular purchasing group (using startup conditions)
...Previous
11.) Creating a rule to determine an approver Transaction PFAC


Procedure to create the function module ZRULE_FM





Adding a flag to the container element for approver determination




Click here to continue..

Triggering approval workflows only for Purchase Orders belonging to
a particular purchasing group (using startup conditions)
...Previous
Just to check if the rule is working fine , we can simulate the rule



We apply this rule to the agent determination of the task display PO in our workflow

The Purchase order needs to be sent for approval to an approvers inbox to be either approved or
rejected. So we need to have a decision step for the same




Click here to continue...

Triggering approval workflows only for Purchase Orders belonging to
a particular purchasing group (using startup conditions)
...Previous
Now we set a flag for the approver determination using the container operation






If approver Clicks No , a mail is sent to the workflow initiator


Click here to continue...

Triggering approval workflows only for Purchase Orders belonging to
a particular purchasing group (using startup conditions)
...Previous
If the approver clicks Yes , the PO is displayed in the ME23N transaction

Now to test the workflow, we can trigger the event manually using the SWUE transaction


The Display PO activity is in the approvers inbox.

The transaction ME23N opens if the approver selects Yes


If a No is selected, the item in the inbox looks this way


Exception Handling in SAP Business Workflow
By Suresh Kumar Parvathaneni
From the release of SAP NW04 version, SAP has introduced many new features among which
exception handling is one.
Exception handling is done in workflow using Blocks (TRY-CATCH mechanism). Blocks is one of the
new features introduced from NW04 version.
This document details about the usage of Blocks and the approach to trigger and handle the exceptions.
Pre-requisites
It is assumed that the reader of this article has some knowledge in SAP workflow and has worked with
the steps Mail, Process control earlier.
Overview of Blocks
Blocks could be treated as folders combining a group of dependent work items. They are shown
as folders in the workflow log.
Each block would have start and end nodes.
Blocks can be deadline monitored (only Latest End)
Blocks can catch exceptions
Following are the screenshots representing how a Block appears in the workflow definition and in the
workflow log:

Fig: Appearance of Block in the Workflow definition.

Fig: Appearance of Block in the Workflow log
A Block is completed only if the dependent work items are complete or in the final state. If a Block is
cancelled, all its dependent work items are cancelled.
Each Block can have its own container elements. All the parent container elements are visible within the
Block.
Defining a Block
Start a new workflow definition using the transaction SWDD
Double-click on the Undefined step and select Block.

Enter the step name and leave the block type as Standard. Press Enter. The workflow definition
would be appearing as follows:

All the dependent steps could be defined with in the Block start and Block end.
Contd..

Exception Handling in SAP Business Workflow
Contd..
As mentioned earlier, Blocks can handle exceptions. If an exception is caught, everything inside the block
is cancelled. If exception is not caught, process is set to an ERROR state (This could be compared to
TRY-CATCH in ABAP
TM
programs. If the exception is not caught, program results in dump)
Create a new workflow and define a new step Block as mentioned earlier page.
In the Block step, click on the tab Exceptions and make an entry of a new exception, for e.g.,
Dummy_Excep, which would be raised in the workflow definition.

Activate the exception defined above, by clicking on the button left to the exception name
Go back to the main screen. Two branches would be appearing between the block begin and
block end, as shown below. Exception branch is taken whenever the exception, Dummy_Excep,
is triggered.

Exceptions are triggered using the step Process Control. Define a new step Process Control in
the normal branch. Enter the step name and the outcome name. Select Throw Exception in the
function. In the event name, select the exception name defined earlier (see the screenshot
below).
Uncheck Step not in workflow log if you would like to see this step in the workflow log.
Define a mail step in the exception branch of the block (for testing purpose to ensure that this
exception branch is taken, when the exception is triggered). The execution flow of the exception
handling is shown below:



SWITCH in multiple condition
By Suresh Kumar Parvathaneni
SAP has introduced new features in Business Workflow in the releases 6.20, NW04 and NW04s.
This Tutorial introduces you to a new feature SWITCH provided in the step Multiple Condition of SAP
Workflow. It is assumed that the reader of this Tutorial has already some knowledge in Business
Workflow and has worked on Multiple Condition step earlier.
The SWITCH feature in the step Multiple Condition is provided from the release NW04. The only feature
available before NW04 with this step is CASE. In the case of CASE, the workflow system checks the
value of the basis of comparison against the defined comparison values (as shown below).

In SWITCH, each branch of it carries a condition definition. We can visualize Multiple Condition with
SWITCH as a group of Condition steps.
Small scenario using Multiple Condition with SWITCH is shown below:
Create a new workflow definition with a container element CARRID (Well known example for training
purposes).

Set the Properties as import.
Double click on the undefined step to create a step Multiple Condition. Following screen appears:

Select the Switch option in the Type field.


Contd..

SWITCH in multiple condition
Contd..
Different types of conditions can be defined for each Outcome. Please note that:
The conditions are defined in the given order.
The first branch whose condition is evaluated TRUE is considered.
If none of the condition is TRUE, a default branch is taken (Other values in the definition).
Following are the conditions used in our example:

The workflow definition would appear as follows:

Insert an email step for each branch and check the output for various Carrid values.

Understanding "Local Workflow"
By Murali, CapGemini
In this tutorial, we would explain creating and working with a local workflow.
Go to Transaction SWDD. Create a new workflow definition.

Go to Basic data (hat symbol) as shown in above screenshot.

Fill-in the Abbreviation and Description and click on the tab Version-Dependent (Current Workflow
Version).

Enter a name for a local event.

Go back to the main screen and create a new step.

Select the step Event Creator. Provide the Step Name and Outcome Name. Also select Trigger Local
Event in the Event Creator.

Enter the name of the event we defined earlier.

Go back to the main screen and create a new step (See the screenshot below)

Select the step Local Workflow

Click here to continue...

Understanding "Local Workflow"
...Previous
In the screen shown below, enter the step name and also event name we created earlier.

Go back to the main screen. In the local workflow definition, right click and click on Create.

Create a new step Mail.

Go back to the main screen. The workflow definition would look as follows:

Activate your workflow and test your workflow definition. You might not be able to find the email in your
SAP inbox. Follow is the screenshot from the workflow log.

When the main workflow is ended, the local workflow would automatically end with a status Logically
deleted. The workflow would continue further after the step Event creator without waiting for the local
workflow to complete.
So let us create a step User Decision after the step Event Creator in the workflow definition.


Activate and test run your workflow definition. You would now observe an email and also work item
regarding the user decision step in your SAP Inbox (see the screenshot below)


SAP Workflow Customization Settings (How to do)
This document details the basic workflow customization that needs to be done in any SAP system before
activating the workflow definitions.
Go to transaction SWU3. <For this demo, we have used an ECC 6.0 IDES system>

The description or the help for each of the above steps are available on the right side of the screen.
Configure RFC Destination
This can be done automatically or manually. If done automatically, as mentioned on the right side frame,
the logical RFC destination WORKFLOW_LOCAL_XXX is created (if not available). XXX is the client
number. Also the user WF-BATCH is also created if not already available.
The advantage of executing the above step manually is we can maintain another user and password as
required.
Select the step Configure RFC destination and click on F9.
If you happen to get the following popup, click on Yes.

Once the RFC destination, you can see the Green Tick mark beside Configure RFC Destination (as
shown in the screenshot below)

Maintain Workflow System Administrator
Since the system being used for this demo is an IDES system, some user is maintained as workflow
administrator. You can change this to the desired User using this step.
Select Maintain Workflow System Administrator and click on F8.

Now you can change the Userid to the desired one.
The steps Maintain Active Plan Version, Classify Decision Task as General, Document
Generation/Form Integration, and Maintain Time Units are already in Green. If not in Green, select the
corresponding step and click on F9. The automatic configuration would be done.
Click here to continue...

SAP Workflow Customization Settings (How to do)
...Previous
Schedule Background Job for Missed Deadlines
This is the job which checks if any work item has
Select this step and click on F8.
There are chances that you might encounter the following error:

To resolve this, you need to maintain the default printer in your user profile of WF-BATCH or change the
printer to a valid one. Go to SWU1 and enter WF-BATCH. Navigate to tab Defaults.

In the above screenshot, the output device is maintained as LP01 which is not valid. Here I am modifying
the same to LOCL. Also the check box Output immediately is marked X.

Save your entries.
Now let us go back to transaction SWU3 and the step Schedule Background Job for Missed Deadlines.
Click on F8.
You would get the following screen:

Depending on the business requirements, we can change the interval to the desired level. However 3
minutes is the minimum duration the system accepts.
Click on Save and Schedule. You would get the prompt for the customization request.
Now similarly schedule the jobs Work items with errors and Condition evaluation.
For the step Schedule Background job for Event Queue, click on F9 (Automatic execution).
See the screenshot below:

Now we can observe the green tick mark beside Maintain Runtime Environment.
Now lets move to Maintain Definition Environment
Click here to continue...

SAP Workflow Customization Settings (How to do)
...Previous
Maintain Prefix Numbers
All the objects related to workflow (standard task, workflow tasks and others) are assigned a eight digit
number. The prefix number is used for the first 3 digits and the rest five is automatically assigned by the
system (starting with 00001).

Select Maintain Prefix Numbers and click on F8.

Click on Display<->Change.

Click on create.

Enter a prefix number which is not allocated to any other client in the system.

Save your entries.
Now you can observe the green tick mark beside Maintain prefix numbers.

Click here to continue...

SAP Workflow Customization Settings (How to do)
...Previous
If you do not intend to work with HCM related workflows, the next step Check Entries from HR Control
Tables is not mandatory.
To maintain this step, please
visithttp://www.saptechnical.com/Tips/Workflow/Customization/HRTables.htm.
After completion of the above step, we can now observe that the steps regarding Maintain Runtime
Environment and Maintain Definition Environment are in green now.

Unless you plan to use the Guided Procedures, the above configuration should be fine to work with the
workflows in SAP R/3.
Now to test the workflow configuration, click on Start verification Workflow (F5). We would get the
following popup message:

Now go to your SAP Inbox to check the work item (Transaction SBWP)

Execute the work item.

We can choose one of the two options to test the workflow configuration. Let us chose the first one.
You would now receive two emails in your SAP inbox:

This completes the workflow configuration.

Useful Transactions in SAP Workflow
Transaction Code Description
OOAW Evaluation paths
PFAC_CHG Change roles
PFAC_DEL Delete roles
PFAC_DIS Display roles
PFAC_INS Create roles
PFOM Maintain assignment to SAP organizational objects
PFOS Display assignment to SAP organizational objects
PFSO Organizational environment of a user
PFTC_CHG Change tasks
PFTC_COP Copy tasks
PFTC_DEL Delete tasks
PFTC_DIS Display tasks
PFTC_INS Create tasks
PPOCW Create organizational plan
PPOMW Maintain organizational plan
PPOSW Display organizational plan
SWDA Workflow Builder (Calls the Workflow Builder in
alphanumeric mode)
SWDD Workflow Builder
SWDS Workflow Builder (Selection)
SWDD_CONFIG Workflow configuration
SBWP The Business Workplace
SWDC_DEFINITION Workflow Builder administration data
SWDC_RUNTIME Workflow runtime administration data
SWNCONFIG Extended notifications for business workflow
SWDM Business Workflow Explorer
SWEINST Evaluation and maintenance of instance linkages

Continued...

Useful Transactions in SAP Workflow
...previous
Transaction Code Description
SWEINSTVC Evaluation and maintenance of instance linkages
SWE2 Evaluation and maintenance of type linkages
SWE3 Evaluation and maintenance of instance linkages
SWE4 Switch event trace on/off
SWEL Display event trace
RSWELOGD Delete event trace
SWEC Link change documents to events
SWED Assign change document objects to object types
SWEQADM_1 Event queue administration
SWEQBROWSER Administration of event queue browser
SWETYPV Evaluation and maintenance of type linkages
SWI1 Selection report for work items
SWI2_FREQ Work items per task
SWI2_DEAD Work items with monitored deadlines
SWI2_DURA Work items by processing duration
SWI11 Tasks in workflows
SWI13 Task profile
SWI5 Workload analysis
SWL1 Settings for dynamic columns
SWLV Maintain work item views
SWFVISU Parameters for Work Item Visualization in the UWL
SWO1 Business Object Builder
SWO6 Customizing object types
SWR_WEBSERVER Customizing Web server
SWU_CONT_PERSISTENCE Administration of container persistence
SWU_EWCD Wizard for event creation using change documents
SWU_EWLIS Wizard for event creation using the Logistics
Information System
SWU_BTE Wizard for event creation using Business Transaction
Events
SWU0 Event simulation
SWU2 RFC monitor
SWU3 Automatic Workflow Customizing
SWU4 Consistency check for standard tasks
SWU5 Consistency check for customer tasks
SWU6 Consistency check for workflow tasks
SWU7 Consistency check for workflow templates
SWU8 Switch workflow trace on/off
SWU9 Display workflow trace
SWU10 Delete workflow trace

Continued...

Useful Transactions in SAP Workflow
...previous
Transaction Code Description
SWUD Diagnostic tools
SWUE Trigger event
SWUI Start workflows/tasks
SWUS Testing workflows/tasks
SWXML Display XML documents
SWUY Wizard for linking messages to workflows
SWWCOND_INSERT Schedule background job for work item deadline
monitoring
SWWCLEAR_INSERT Schedule background job for clearing tasks
RSWWCOND Execute single background job for work item deadline
monitoring
RSWWCLEAR Execute work item clearing work once
WF_HANDCUST WebFlow service handler maintenance
WF_EXTSRV Maintain Web Service Repository
WFWS Import WSDL files

También podría gustarte