转 How to Trigger Class based workflow

How to Trigger Class based workflow

By Rakesh Dhudipala from Link

Scenario:

This explains a simple scenario to trigger Class based Workflow from program.  

Step by Step procedure:  

Go to SE24 transaction and create a class with ZCL_WEBDYNPRO_WF.

转 How to Trigger Class based workflow

Go to Interfaces tab and implement the interface IF_WORKFLOW

转 How to Trigger Class based workflow

Go events tab and create a event trigger with parameter i_kunnr.

转 How to Trigger Class based workflow
Go to methods tab and and implement the SET_CUTOMER method with I_KUNNR as importing parameter.

转 How to Trigger Class based workflow

Set_customer method write the below code.  

method set_customer.

* Data Declarations
  DATA: lv_class            TYPE sibftypeid,
        lv_event             TYPE sibfevent,
         lv_objkey           TYPE sibfinstid,
  lr_event_parameters TYPE REF TO if_swf_ifs_parameter_container,
  lv_param_name       TYPE swfdname,
  lv_id               TYPE char10.


  lv_class = 'ZCL_WEBDYNPRO_WF'.
  lv_event   = 'TRIGGER'.

* Instantiate an empty event container
  CALL METHOD cl_swf_evt_event=>get_event_container
    EXPORTING
      im_objcateg  = cl_swf_evt_event=>mc_objcateg_cl
      im_objtype   = lv_class
      im_event     = lv_event
    RECEIVING
      re_reference = lr_event_parameters.

* Set up the name/value pair to be added to the container
  lv_param_name  = 'I_KUNNR'.  " parameter name of the event
  lv_id          =  i_kunnr.


  TRY.
      CALL METHOD lr_event_parameters->set
        EXPORTING
          name  = lv_param_name
          value = lv_id.

    CATCH cx_swf_cnt_cont_access_denied .
    CATCH cx_swf_cnt_elem_access_denied .
    CATCH cx_swf_cnt_elem_not_found .
    CATCH cx_swf_cnt_elem_type_conflict .
    CATCH cx_swf_cnt_unit_type_conflict .
    CATCH cx_swf_cnt_elem_def_invalid .
    CATCH cx_swf_cnt_container .
  ENDTRY.

* Raise the event passing the event container
  TRY.
      CALL METHOD cl_swf_evt_event=>raise
        EXPORTING
          im_objcateg        = cl_swf_evt_event=>mc_objcateg_cl
          im_objtype         = lv_class
          im_event           = lv_event
          im_objkey          = lv_objkey
          im_event_container = lr_event_parameters.
    CATCH cx_swf_evt_invalid_objtype .
    CATCH cx_swf_evt_invalid_event .
  ENDTRY.

  COMMIT WORK.

endmethod.  

Go to SWDD transaction and create a new workflow called ZTEST_WF  

转 How to Trigger Class based workflow

Go to header and Start events tab and enter the below details  

转 How to Trigger Class based workflow

 

Now if we call the SET_CUSTOMER method it will trigger the ZTEST_WF workflow.

相关推荐