`
evangxli
  • 浏览: 230748 次
  • 性别: Icon_minigender_1
  • 来自: 大连
社区版块
存档分类
最新评论

转 Program Exits in Work Item for Workflow

 
阅读更多

Program Exits in Work Item for Workflow

By Anirban Bhattacharjee, KPIT Cummins and Infosystems from Link

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 the IF_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 value ‘sap.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.

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_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
  
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_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
  
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.

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.

分享到:
评论

相关推荐

    User Exits in SAP BW

    在SAP BW(Business Warehouse)系统中,用户退出(User Exits)是一种关键的自定义和扩展机制,它允许客户根据自身业务需求对标准SAP交易进行调整和优化,而无需直接修改原始代码。这样做可以降低维护成本,因为当...

    User Exits,Customer Exits,BAdI and BTE

    在SAP系统中,"User Exits"、"Customer Exits"、"BAdIs"(Business Add-Ins)和"BTEs"(Business Transaction Events)是四种关键的扩展机制,它们允许用户根据业务需求定制标准软件功能。下面将详细阐述这四种技术...

    PostgreSQL IN vs EXISTS vs ANYALL vs JOIN性能分析

    PostgreSQL作为一种强大的开源关系数据库系统,它支持多种SQL操作,其中包括IN、EXISTS、ANY/ALL和JOIN等操作符。这些操作符在不同的业务场景下有着不同的表现和性能影响。在实际的数据库操作中,选择合适的操作符是...

    8-07-14_MegaCLI for linux_windows

    LSIP200232921 (DFCT) MegaCLI displays version for PD in unclear format and the data is not aligned correctly LSIP200232954 (DFCT) Need to Support all the MFC default values in the command AdpSettings...

    exits完全退出

    for (Activity activity : activityList) { activity.finish(); } // 彻底退出应用 System.exit(0); } } ``` #### 2. 初始化`MyApplication` 接下来,在每个活动的`onCreate()`方法中初始化`MyApplication`...

    sap 增强 badi userexit customerexit

    FM exits在关联的Function Group中的命名规则为:EXIT_program name_nnnCustomer exits的调用方式为: * FM Exits:CALL CUSTOMER-FUNCTION 'xxx' EXPORTING ... IMPORTING ... * Subscreen:Call CUSTOMER-...

    PM USER EXITS

    标题:“PM USER EXITS” 描述:此文档详细介绍了在SAP PM(Plant Maintenance)模块中的用户出口(User Exits),并特别关注了ABAP语言的使用。用户出口是SAP系统提供的一种定制化机制,允许企业在标准流程中插入...

    Solution Paper 1913190.pdf

    As a result, in this case, both time for visitors’evacuation and time for road-planning are essential reference points for the system. A simple and robust model will surely be better.

    Turbo C++ 3.0[DISK]

    be given instructions in a box at the bottom of the screen for each prompt. For example, if you will be installing from drive A:, type: A: INSTALL - This INSTALL handles the installation of ...

    Turbo C++ 3.00[DISK]

    be given instructions in a box at the bottom of the screen for each prompt. For example, if you will be installing from drive A:, type: A: INSTALL - This INSTALL handles the installation of ...

    EXIT FOR STUDY

    SAP USER EXITS FOR DEVELOPER

    Z_FIND_USEREXIT_SAP增强查找Z_USEREXIT_

    标题中的"Z_FIND_USEREXIT_SAP增强查找Z_USEREXIT_" 提到的是一个专门用于寻找和管理SAP用户出口(User Exits)的工具。用户出口是SAP提供的一种预定义的扩展点,允许开发人员在不修改标准代码的情况下插入自定义...

    DME.rar_DME_decide

    Java program will spawn n (distributed) processes Pi, 0 ≤ i < n, each one looping forever. Each loop iteration is a loop interval. In every loop interval Pi does the following: &#8722 It sleeps ...

    tor-exits:处理 Node.js 中的 Tor 出口节点

    Tor退出安装 npm install tor-exits用法 var tor = require ( 'tor-exits' ) ;tor . fetch ( function ( err , data ) { if ( err ) return console . error ( err ) ; var nodes = tor . parse ( data ) ; console ...

    Determining the stack usage of applications.pdf

    In an RTOS, each thread has a separate memory region for its stack. During function execution, data may be added on top of the stack; when the function exits, it removes that data from the stack.

    Python程序设计(第二版).chm

    Program Exits Section 3.5. Interprocess Communication Section 3.6. Pipes Section 3.7. Signals Section 3.8. Launching Programs on Windows Section 3.9. Other System Tools Chapter 4. ...

    SAP增强查找工具程序SAP增强工具程序

    - `P_PROGDisplay program exits`:用于显示程序退出点。 - `P_SUBMShow submits`:用于显示提交程序。 - `P_TCODETransaction code`:用于输入事务代码。 - `P_TEXTSearch for text`:用于搜索文本。 - `P_...

    2019 ICM PROBLEM D: Emergency exits. (2019 美赛 D 题: 用元胞自动机模拟逃生出口问

    标题中的“2019 ICM PROBLEM D: Emergency exits”指的是2019年美国国际数学建模竞赛(ICM)的D题,该题目涉及的主题是利用元胞自动机来模拟紧急出口的情况。这是一个典型的数学建模问题,旨在通过数学方法解决实际...

    WINCC读写SQL数据库的例子

    在工业自动化领域,SIMATIC WinCC是西门子推出的一款人机界面(HMI)软件,用于监控和数据采集。本文将深入探讨如何利用WinCC与SQL数据库进行交互,包括读取和写入数据,以实现更高效的数据管理和分析。...

    droplol::mobile_phone_with_arrow:drop.lol CLI客户端,可轻松进行对等文件传输

    the file is sent and then the program exits.When no file is provided, the program will receive all files andsave them in the current directory.全局安装( npm install -g droplol )时,该命令可以作为...

Global site tag (gtag.js) - Google Analytics