Skip to end of metadata
Go to start of metadata

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.

      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.

       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.

     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.

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.


7 Comments

  1. The scenario is very well explained and provided with neat example, clear and to the point.
    Thank you.

    with regards,

    Sudhahar R

  2. Thank you Sudhahar Ramachandran

  3. Dear Mr Pavan Bhamidipati,

     It is a very good article indeed. A big Thank you.

    As you mentioned in this article that  "Program Exits can be used 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."

    Can you please give some more examples if convenient?

    Also I am new to workflow and learning it, I will greatly appreciate your help if you can provide some more material (or link to them if they already exist on internet) on other advance features of SAP workflow/webflow.

    Kind regards,

    BKSinghal@hotmail.com

  4. Former Member

    Hi,

    This is great information.  Thaank you.  I am having trouble updating the workitem from the program exit.  I am getting a workitem locked error.  Can work items be updated within a program exit?

    Regards,

    tamanika.ivie-smith@wbconsultant.com

  5. Unknown User (izvm8o8)

    Thanks for this useful tip!

    However, I want to know how to use the method SET_DEBUG from interface IF_WAPI_WORKITEM_CONTEXT.

    I have used this method and set the importing paramater of this method to 'X' to activate the debugging but I do not what to execute to debug this program exit. It does not turn to debug mode when I triggered the workflow.

    Thanks,

     ericaguinaga@yahoo.com

  6. Former Member

     

    very useful document

  7. Nice helpful document.