SAP Virtual/Onsite Trainings

Document Categories:

What's New?

Contribute?

Sample Specs

What's Hot?

Web Dynpro for ABAP Tutorials 


Join the Mailing List
Enter name and email address below:
Name:
Email:
Subscribe  Unsubscribe 

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

Click here to continue..

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image