5/31/2019»»Friday

How To Call Workflow From Abap Program Sap

5/31/2019
    23 - Comments
How To Call Workflow From Abap Program Sap Rating: 7,4/10 5387 votes
Skip to end of metadataGo to start of metadata

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.

General Scenario where you can use:

In General, we may come across the scenarios where, when ever a work item is created, or executed, we may need to update the database tables or we need to execute a separate task in background or we may need to get the workflow container values and manipulate them dynamically at run time and set the new values to the workflow container elements. In these sorts of cases we can use Program Exits in the workflows.

A Considered Case to explain the use of program exits:

A ZWORKITEM_INFO table with 7 fields

Field

Data Element

Description

WI_ID

SWW_WIID

Work item ID

WI_TYPE

SWW_WITYPE

Work item type

WI_CREATOR

SWW_OBJID

Creator of work item

WI_RH_TASK

SWW_TASK

Task ID

WI_PRIO

SWW_PRIO

Priority of work item

WI_CD

SWW_CD

Creation date of work item

WI_EXECUTED

CHAR1

Confirmation of execution


Include a Decision step in the workflow whenever the respective work item is created an entry is inserted in the table ZWORKITEM_INFO. Once the work item is executed from SBWP, field WI_EXECUTED of the above table is set to 'X'.

Understanding the Interface IF_SWF_IFS_WORKITEM_EXIT:

IF_SWF_IFS_WORKITEM_EXIT is a Runtime Exit Workflow Interface. If you look at the interface it consists of one method EVENT RAISED and attributes are of CONSTANT type belong to SWW_EVTTYP Event Type for Workflow Runtime. This interface includes a type-group SWRCO which contains all the constant attribute values that are used in this interface like SWRCO_EVENT_AFTER_CREATE etc.

Sap

The following are the possible predefined events that can occur with respect to a work item.

  • Before Creation
  • After Creation
  • Before Execution
  • After Execution
  • After Execution of a Synchronous Object Method
  • Before Physical Deletion
  • After a Status Change
  • After Rule Execution
  • After an Action
  • Before an Action

As it has been already mentioned in the SAP help documentation that, the classes are used in the Program Exits tab must support the interface IF_SWF_IFS_WORKITEM_EXIT and this class must not have any call to the RFC function modules, or it must not contain any statements like COMMIT_WORK, ROLL BACK etc.

Defining the ABAP Class that Supports IF_SWF_IFS_WORKITEM_EXIT

Properties of the ABAP class should be as shown in the screen shot and add the type group SWRCO.

In the Interface tab add the interface IF_SWF_IFS_WORITEM_EXIT. After adding the interface look at the ATTRIBUTES tab it will be like the below screen.

Here we need to define two more attributes along with the included attributes they should be Instance specific and private and I have declared WI_CONTEXT as type ref to one more interface IF_WAPI_WORKITEM_CONTEXT this interface will provide you the current context for the work item. PROCESS_STATUS is another attribute which define the name of the property for semantic process status and initial value must be assigned as 'sap.bc.bmt.wfm.process.status'.

Check the METHOD Tab it will have one method included by default when you include the interface IF_SWF_IFS_WORKITEM_EXIT.

Here I have defined two more methods to handle the predefined events of the work item. Now implement the method of the interface EVENT_RASIED. The minimum code that is required to validate the event name and which method should act as event handler.

How to call workflow from abap program sap bw

After execution of the Event Raised method the attribute WI_CONTEXT will have the current context (Current Status of the work item) of work item. i.e. the instance of the interface IF_WAPI_WORKITEM_CONTEXT is created.Once the instance of the IF_WAPI_WORKITEN_CONTEXT is created then by using its different methods, we can retrieve the information related to the workitem.

Call Transaction From Abap Program

The interface IF_WAPI_WORKITEM_CONTEXT has the following methods by which we can retrieve the information that is needed about the work item.To see full list of methods, execute SE24 enter the interface name and click on the Methods tab.

Implementation of AFETR_CREATION ( ) method

In this method implementation observe the CALL METHOD statement where it is calling get_header method which belongs to the interface IF_WAPI_WORKITEM_CONTEXT, which will return the header information of the workitem for more information about the header information open the structure SWR_WIHDR in SE11.

Send email from abap program

Implementation of AFTER_EXECUTION ( ) method.

The same work item context is used in the AFTER_EXECUTION method to get the work item ID See the CALL METHOD statement in the AFTER_EXECUTION method.

Design the workflow having a simple Decision step and in the program exits tab include the class ZCLPROGRAM_EXIT_WORKFLOW Activate and execute the workflow. An entry is made in the table but the WI_EXECUTED field will not have any value. Now execute the work item from the SAP inbox (SBWP). Now the WI_EXECUTED field in the table will be updated by X.