How To Call Workflow From Abap Program Sap

  1. Call Transaction From Abap Program
Skip to end of metadataGo to start of metadata

What are advantages of SAP Business Workflows?

A business process can consist of several steps. Historically, the
tasks have been coordinated manually or by some informal means
of communication (sticky note, e-mail, shouting, and so on).
The common problem in these approaches is :

Defining a Range in Module Pool Program. Trigger workflow when a record is created in a database table. SAP, SAP R/3, R/3 software, mySAP, ABAP. This example shows a simple way to call a workflow process from Event-Class into a Class Method or SAP ABAP Program. Create a reference to SAP Business Interface in our class (trx SE24). With this way we are able to use our SAP ABAP Class into SAP Business Workflow Event Containers. Please add the interface parameters below. An SAP user has created a user decision step in an SAP workflow item and wants to know how an end user can send an attachment to other users. Continue Reading How to hide a button in an SAP Business Workplace toolbar.

  • Inefficiency
  • Each lacks a way to trace where a task is
  • Who executed(or is executing it),
  • How much time it requires.

In contrast, the workflow ensures that the right work is sent to the right person at the right time in the right sequence with the right information.

  • Workflow is a tool for automization of business processes
  • Not tied up to any particular application
  • Operates uniformly across applications
  • Coordinate all participating tasks
  • Provide users with active support
  • Deadline Management is possible

Workflows are very useful for business processes that:

  • Contain a sequence of activities.
  • Reoccur in the same or similar forms.
  • Involve several people or groups of people.
  • Require considerable coordination.

What are the layers in Workflow Architecture?

There are 3 layers in the Workflow Architecture:

  • Business Object
  • Business Process
  • Organization Model

How Process, Business Logic and People are linked in Workflows?

  • The business processes are defined in Workflow builder. Each and every small work process is called as an activity in the workflow builder. Each activity consists of a single step task, which can be a standard task or a workflow template.
  • Associated Business Logic is built in Business Objects. i.e. ABAP code will be in Business Object. Business Objects consist of attributes, methods and events. Methods consist of ABAP code. Each and every standard task is associated with a Business Object and a method.
  • People / Group of people responsible for taking actions are defined in organization structure. Person responsible for taking an action is called actual agent. It is defined in the workflow activity.

What is a Business Object?

Business object (BO) is basically collection of Attributes, Methods and Events for a particular business entity. Example of BO: Sale Order, Vendor, Customer, Material etc.
BOs wrap around backend tables, application code, change document and other technical information and expose them as Attributes, Methods and Events. Usually methods of BOs refer to BAPIs.

The following diagram explains BO much better:

What is an Agent and what are different types of Agent?

An agent is a person or a group of persons who can take an action during workflow runtime. Action can be approval of some business document, creation of some document or sending email.

There are basically three types of Agents:

  • Actual Agent: One who actually takes the action. This is provided in the workflow Activity.
  • Possible Agent: All possible persons/entities that can execute a task during runtime. Defines either in Org Structure or task.
  • Excluded Agents: Persons who are excluded from taking action on a task. These are assigned in the workflow definition at the workflow activity.

System checks Actual Agent defined in workflow runtime with the Possible Agents defined in the task and the Excluded Agents. Actual Agent should be a subset of Possible Agents minus the Excluded Agents, else Agent resolution fails.

What are the capabilities of Workflow Builder?

What are Events?

Events are actions that occur in the system and that acts as trigger point for any workflow. Eg. Sales order creation. is an event.

Eg; Consider a scenario where any sales order after creation subject to approval from superior. So here a workflow comes into play. The workflow needs to start whenever a Sales order is created. The business object BUS2032 is associated to sales order creation. It has event CREATED. So the trigger point or ' START EVENTS ' in the workflow is the BUS2032 's event CREATED.

Then bind the event to the workflow so the data flows from event to the Workflow. e.g.: Sales order is created. So for the workflow to proceed it'll need sales order details. With binding the respective values is mapped ito the workflow container.

Then activate the linkage once you are through the workflow creation. This is important as after this only the workflow will listen for the event, in the sense that after this only the workflow is triggered on the event. This is critical also as each active link adds to system load considerably and too many workflows in the test environment can bring the system down. So careful. Deactivate once test is over and workflow is no longer used.

What are the various methos of creating Events?

The various metods of creating Events are:-

- Function module - event creation by calling function module
SWE_EVENT_CREATEorSAP_WAPI_CREATE_EVENT.
- Change documents
- Event creation when change documents are written.
- General status management
- Logistics Information System (LIS)
- Eventcreation upon status changes.
- Business Transaction Events
- Message Control

How can an Event be linked with a Workflow ?

Consider the start of any workflow. The START EVENTS tab is taken through the header. The Business Object is specified and binding is generated to the workflow to receive the values and then the link is activated.See the pic below for the Sales Order creation as start event for a workflow.
back to top

What are containers, Binding and Binding Editor?

Containers are nothing but the Variables in the Workflow that hold the values in the workflow. They can be simple variables or structures or even objects of any class. So they are best treated as the variables. Binding as explained above is passing the values from events, methods and other externals sources to the container. When an event is binded to the workflow then the data automatically flows from the Event to the Container in the workflow. Binding editor is there as automatic binding may not always pick up the right or desired binding or precisely the mapping generated may not be appropriate or as required due to technical reasons which any techie can guess. So editor gives an option to the developer to edit or generate manually.

What are important Transactions and Reports?

The area menu 'SWLD' lists all the transactions associated with Business workflows.

SWDD - Main Workflow Builder.

PFTC - General task maintenance.

SWO1- Business Object Builder.

SBWP- The Business Workplace SWDM - Business Workflow Explorer

SWELS - Switch Event Trace On/Off

SWETYPV - Display/Maint. Event Type Linkages

SWUS - Test Workflow

SWUI - Start Workflow

SWI6 - Workflow for Objects

SW14 - Workflows for Objects Types

SWDB - Workflow Builder - Create Workflow

SWLV - Maintain Views

TASK/TASK GROUPS

PFTC_INS - Create

PFTC_CHG - Change

PFTC_DIS - Display

PFTC_COP - Copy Pideme lo que quieras o dejame pdf.

PFTC_DEL - Delete

Tcodes Related To Events

Email application download nokia 5233. Events Creation

BSVW - Status management

NACE - Message Control

AWUW - Logistics Information System (LIS)

Event Linkages

SWB_COND - Workflow Start Conditions

Work item analysis

SWI2_FREQ - Work Items Per Task

SWI2_DEAD - Work Items With Monitored Deadlines

Send email from abap program

SWI2_DURA - Work Items By Processing Duration

Ham

Task analysis

SWI11 - Tasks in Workflows

SWI13 - Task profile

For more SAP Business Workflow Transactions,check the link :- http://help.sap.com/saphelp_40b/helpdata/en/9b/572614f6ca11d1952e0000e82dec10/content.htm

Where can I find more details about workflows?

SAP Help - Business Workflows
SDN Forums
SDN Blogs for Workflows
SAP Business Workflow FAQ

Exception in binding of Task and the Method?

It is observed that when we bind a Task with any BO Method then all the fields defined for binding are wiped out after we save the binding i.e. if we want to see the fields taking part in binding of the TASK & METHOD or while binding the work flow and the TASK it is observed that the container elements and task container elements disappear even though binding is established. This happens because of inconsistent buffer synchronization.

To overcome this issue follow the steps in SWDD.

Menu->Extras->Transport->Synchronize runtime buffer, or go to TCODE SWU_OBUF of buffer synchronization.
back to top

Basic Function Modules in Workflows?

SWW_WI_POPUP_FOR_COMPLETION ' shows the compeleted status of a workflow

SWW_ADDR_KEY_CREATE_FROM_USER ' display the address of the user or recipient

SWW_WI_DELETE ' delete work item

SWW_WI_CREATE_VIA_EVENT ' create work item as result of event

SWW_WI_DEADLINE_CHANGE ' change of deadline attribute of work item

SWW_WI_COMP_EVENT_RECEIVE ' complete workitem using events

SWW_WI_REJECT ' reject work item

SWW_WI_EVENT_RECEIVE ' retrive event for a workflow

SWW_WI_DISABLE ' lock workitem against execution

SWW_WI_ENABLE ' remove lock against execution of workitem

Page:Accessing Single Entry from Multi-line ElementPage:Approval Decision on Approve or Reject with Reasons or CommentsPage:Approving a Workflow from GMailPage:Binding Definition in WorkflowPage:BOM in workflows!What and how?Page:Converting Smartform to PDF in WorkflowsPage:Deadline MonitoringPage:Delegation and Redefining methods of business object BUS1001Page:Differences between a Work item and an emailPage:Display Users details in RulesPage:Document Template in WorkflowPage:Event Creator & Wait Step UsePage:Exception handling in WorkflowsPage:Extended Workflow NotificationPage:Function Module to evaluate what are the function modules suitable for a given generated Work Item.Page:Hello All,Page:How to find an Event for any transaction for triggering of a workflowPage:How to find which organization unit you are currently being assigned toPage:How to Handle User Decesion in WorkflowPage:How to make FORM in workflow?Page:How to send an external mail from workflowPage:Marking the material for deletion using SAP Business Workflow - triggering the redefined methods of a Business ObjectPage:Need to delete entries from table SWFREVTLOGPage:Organizational Plan in WorkflowsPage:Program Exits In WorkflowPage:Real Estate Contract WorkflowPage:SAP Workflow EVENTSPage:SDN Blogs for WorkflowsPage:Secondary Methods, Before and After MethodsPage:Send an External mail through SAP Business Workflow and Recievers address in CCPage:Simple Report to display Task or Workflow Container DefinitionPage:Tasks in WorkflowsPage:Triggering the workflow by releasing a purchase requisition and automatically creating a Purchase OrderPage:Troubleshooting Workflow Terminating EventsPage:Version Management In WorkflowsPage:Why use SAP Workflow?Page:Workflow for Customer Blocking and UnBlockingPage:Workflow Scenario for PO ChangePage:Work Item intimation in the Email
Skip to end of metadataGo to start of metadata

In the previous blogs of this series, I talked about why we want to use ABAP OO with workflow and how to make an ABAP Class workflow-ready. This blog deals with using a workflow-ready ABAP Class directly in the simplest type of workflow - a single-step task.

How do I know if I'm ready for this?

If you haven't read the first two blogs yet, do that now.
1. Why use ABAP OO with Workflow?
2. Getting started with ABAP OO for Workflow .. using the IF_WORKFLOW interface

If you want to try the exercise in this blog in your own system, you will need an ABAP Class with the IF_WORKFLOW interface, and a system/client (SAPNetWeaver 6.20 minimum) with the workflow environment activated. If you aren't sure if your workflow environment is activated, check transaction SWU3 in your system to quickly view and activate the workflow environment in your system. Make sure both the definition and runtime environments are activated, so you can create a task and then test it.

As mentioned in the last blog, this blog won't teach you ABAP OO. It won't teach you workflow either, but it should give you enough to get going even if you've never touched workflow before.

Note: I've based the examples on an ABAP Class representing a Plant as this is a well known business entity in most R/3 and ECC systems. However if you are not in a suitable system or just don't want to use a Plant example for whatever reason, you can use your own business entity. All you will need for this exercise is an entity with a key (preferably less than 32 characters in length) and some code to call a display user interface (transaction, function, whatever) for your entity.

How do I use an ABAP OO method in a Task?

The simplest type of workflow is a single-step task, i.e. a piece of work that does one thing only. In ABAP OO terms, a single-step task calls one method only to perform this piece of work. In future blogs we'll deal with multi-step workflows, but as multi-step workflows essentially organise single-step tasks, single-step tasks are a good place to start when building workflows.
In the last blog I mentioned that you cannot call any method inherited from the IF_WORKFLOW interface directly. So to start we need an additional method in the ABAP Class example we have been creating.

The simplest type of method for this purpose is a Public, Instance method with no parameters. A classic example of this is a DISPLAY method. Now of course the code in the method will vary depending on what you are displaying. Here is the code needed to display a Plant in a typical R/3 or ECC system. method DISPLAY .
data: ls_vt001w type v_t001w.

CLEAR ls_vT001W.
ls_VT001W-MANDT = SY-MANDT.
ls_VT001W-WERKS = me->PLANT.
CALL FUNCTION 'VIEW_MAINTENANCE_SINGLE_ENTRY'
EXPORTING
ACTION = 'SHOW'
VIEW_NAME = 'V_T001W'
CHANGING
ENTRY = ls_vT001W.

endmethod.

Have you noticed that I have used an attribute of the class called PLANT? This is the key (Public, Instance) attribute of my class (data type is WERKS). Make sure you add this attribute to the ABAP Class before you activate your new method.

How do you set up the value of Plant? Well of course to create an instance of an ABAP Class in the first place we need a CONSTRUCTOR method, and it's in this method that we fill the attribute plant.

Note: Make sure you use theCreate Constructorbutton to add the constructor method to your class.

As our ABAP Class represents a business entity, rather than a technical entity, an instance is meaningless without having this key attribute provided. So add an import parameter PLANT (data type WERKS) to the CONSTRUCTOR class so that the plant id can be provided during instantiation.

Here is some very simple code for the CONSTRUCTOR method. METHOD constructor .
me->plant = plant.
ENDMETHOD.

Tip! Don't forget to activate and test your class in transaction SE24 before contuining.
Now that we can instantiate the ABAP Class and have a method, DISPLAY, that we can call from workflow, we are ready to include the method in a single-step task.

Abap

To create a single-step task, go to transaction PFTC_INS. Choose the task type 'TS' (Standard Task, i.e. a single-step task) and press the Create button.

On the second screen the real work begins. On the Basic Data tab, give your task an abbreviation, name, and work item text - these are all free text fields so enter whatever you like. Then choose Object Category 'ABAP Class', enter your ABAP Class as the Object Type, and your DISPLAY method as Method.

Note: If you are in a 6.20 system and can't see the Object Category choice 'ABAP Class', then you first need to execute reportSWF_CATIDto enable 'ABAP Classes' as an available object category. It's already done for you in releases 6.40 and higher.

Move across to the Container tab. This is the workflow data storage area - think of it as the equivalent of a data declaration area in a program. You'll notice that workflow has automatically added a container element (equivalent of a data variable in a program) to hold an instance of your class. It's even marked it as available for import/export from the task to other workflow objects such as multi-step tasks and events. You can drill down on the container element if you want to see more.

Save your task, and then there's two things we still need to do before you can test it.

  1. You need to clarify how the system will know when this task is complete. For a display task this is easy.. running the method is all we have to do, nothing has to be changed on a database or synchronised with another system. So all that's needed is to check the flag Synchronous object method below the Method field on the Basic Data tab, and save the task again.
  2. You need to specify who is allowed to execute this task. For simplicity's sake, you can let anyone execute the task by making the task a General Task. Follow the menu path Additional Data - Agent Assignment - Maintain. Place your cursor on the task name, and press the Attributes.. button. Select the General Task radio button, press enter and Save your task again.

Finally make a note of your task number and go to transaction SWUS to test your task. Type in your task id ('TS' followed by the task number) and press Enter. You'll see the import container elements listed below. You'll need to fill in which plant we want to display. Select the container element _WI_Object_Id and the local persistent object reference to your class is displayed below. Type a valid plant id into the field INSTID, and press Enter.

Now simply press the Execute button in the top left hand corner of the screen and you should see the plant details displayed. That's it!

How do I explicitly instantiate an instance in a Task?

Last time I mentioned that you can't call the special method CONSTRUCTOR directly from a task. Usually that's not a problem for workflow as we would use an event to implicitly create the instance and pass that in as we started the workflow.

I'll talk about events in the next blog, but there are occasions when you do want to explicitly create an instance in a workflow step. For example it can be more convenient to instantiate an object based on a flat value attribute of another object, rather than risk potentially recursive code by making the attribute an object instance itself. Or you might simply want to take one of the standard workflow tracked fields, such as the user id that executed a previous workflow step, and get more details, such as the user's name.

This is also a good chance to look at:

  • Using method parameters with workflow
  • Using background methods with workflow

Start by creating a static, public method in your class - call it CREATEINSTANCE. The purpose of this method is to import a plant id and export an instance of the plant class. Make sure you create a suitable signature (import/export parameters) for your method.

Inside the class all you need to do is to call the create object command to create the instance. Don't worry about error handling at this stage .. we'll cover that in a later blog. METHOD createinstance.
TRY.
CREATE OBJECT eo_plantinst
EXPORTING
plant = iv_plant
.
CATCH cx_bo_error .
ENDTRY.
ENDMETHOD.

Note: Don't forget to syntax check, activate, and test your method works before using it in workflow.

Create a task with your CREATEINSTANCE method just as you did with the DISPLAY method. You'll be asked if you want to 'Transfer missing elements from the object method?' - Answer 'yes' and you'll notice that the import and export parameters of your method are automatically added to the task container.

This sort of task is a technical step that is called in background by the workflow system, rather than being executed by a user, so instead of making the task a General Task, mark task as a Background processing in the Execution section of the task (below the method on the Basic Data tab). Don't forget to check the flag Synchronous object method and save again as we did for the DISPLAY task.

Test your new task using SWUS. Fill the import parameter IV_PLANT with a plant id, e.g. 1000, then press the Execute function. Because the task is executed in background we need to look at the workflow log to see if it worked. Use the Workflow log button display the work item. Then use menu path Extras > Container to see the end result. You should see the container element EO_PLANTINST has an valid reference to the plant class.

What about functional methods?

Functional methods (i.e. a method with a RETURNING parameter) can be used as above, or you can also use them in workflow bindings (think 'parameter passing' between different parts of a multi-step workflow). However at this stage, you only have a single-step task to work with so I'm going to leave how to use functional methods in a binding until later in this blog series by which time I'll have expanded our workflow example a little further.

How do I call the task from an application?

Although it's possible to call a task directly, e.g. using standard workflow API functions such as SAP_WAPI_START_WORKFLOW, that's not usually the best way to tackle this very common scenario. In general, we call a task by raising an event which then use to trigger the task. So the next blog will be on using ABAP OO events as workflow events.

Call Transaction From Abap Program

Page:Raising ABAP OO events for workflow