Quantcast
Channel: SCN : Unanswered Discussions - SAP Business Process Management
Viewing all articles
Browse latest Browse all 3160

Invoking a workflow from a class

$
0
0

Hi Experts

 

I am new to workflow and am trying the following

Sending some data from a class and trigger a workflow

 

From the samples I found on ****************

but it errors out on the code (colored in RED)

 

Do we have any documentation or sample inside SAP so that I can learn how to achieve this?

 

 

Thanks in advance

 

REPORT Z_TRIGGER_WF.

 

 

DATA g_evt_param_container   TYPE REF TO if_swf_cnt_container.

DATA g_obj_category          TYPE swfeclstyp VALUE 'CL'.

 

DATA it_description          TYPE STANDARD TABLE OF swc_value.

 

DATA l_event_ref             TYPE REF TO if_swf_evt_event.

DATA l_objtype               TYPE sibftypeid VALUE 'ZCL_TRIGGER_MULTILINE'.

DATA l_event                 TYPE swo_event VALUE 'TRIGGER'.

DATA l_objkey                TYPE swo_typeid.

DATA l_selected_handlers     TYPE i.

DATA l_event_container       TYPE REF TO if_swf_ifs_parameter_container.

 

DATA vl_returncode           TYPE sysubrc.

 

DATA l_return                TYPE swf_return.

 

DATA lex_root                TYPE REF TO cx_root.

DATA l_string                TYPE string.

 

***

 

PARAMETERS p_name            TYPE STRING.

 

* Instantiate the specific container for the class event

TRY.

     CALL METHOD cl_swf_evt_utilities=>get_specific_container

       EXPORTING

         im_objcateg  = g_obj_category

         im_objtype   = l_objtype

         im_event     = l_event

       RECEIVING

         re_container = g_evt_param_container.

   CATCH cx_swf_evt_exception.

ENDTRY.

 

* Aggregate single parameter to event container

TRY.

     CALL METHOD g_evt_param_container->if_swf_ifs_parameter_container~set

       EXPORTING

         name       = 'ENAME'

         value      = p_name

       IMPORTING

         returncode = vl_returncode.

 

   CATCH cx_swf_cnt_cont_access_denied

         cx_swf_cnt_elem_not_found

         cx_swf_cnt_elem_access_denied

         cx_swf_cnt_elem_type_conflict

         cx_swf_cnt_unit_type_conflict

         cx_swf_cnt_elem_def_invalid

         cx_swf_cnt_invalid_qname

         cx_swf_cnt_container.

ENDTRY.

 

 

* Aggregate multiline parameter to event container

 

APPEND 'This is a test with ABAP classes' TO it_description.

APPEND 'for passing a multiline parameter' TO it_description.

APPEND 'to a container of an event' TO it_description.

APPEND 'in order to execute a Workflow.' TO it_description.

 

TRY.

    CALL METHOD g_evt_param_container->if_swf_ifs_parameter_container~set

       EXPORTING

         name       = 'DESCRIPTION'

         value      = it_description

       IMPORTING

         returncode = vl_returncode.

 

   CATCH cx_swf_cnt_cont_access_denied

         cx_swf_cnt_elem_not_found

         cx_swf_cnt_elem_access_denied

         cx_swf_cnt_elem_type_conflict

         cx_swf_cnt_unit_type_conflict

         cx_swf_cnt_elem_def_invalid

         cx_swf_cnt_invalid_qname

         cx_swf_cnt_container.

ENDTRY.

 

*-----------------------------------------------------------------------

*- Check the Container, if all obligatory elements are filled

*-----------------------------------------------------------------------

IF g_evt_param_container IS BOUND.

   TRY.

       CALL METHOD g_evt_param_container->check

         EXPORTING

           check_oblig_parameters  = 'X'

           check_oblig_not_initial = 'X'.

     CATCH cx_swf_cnt_elem_check_failed.

 

   ENDTRY.

ENDIF.

 

*---- move the event-parameters (only if they exist)

IF g_evt_param_container IS BOUND.

   IF g_evt_param_container->get_element_count( ) > 0.

     l_event_container ?= g_evt_param_container.

   ENDIF.

ENDIF.

 

  l_objkey = '12345'.

 

*---- get a instance for the event

CALL METHOD cl_swf_evt_event=>get_instance

   EXPORTING

     im_objcateg        = g_obj_category

     im_objtype         = l_objtype

     im_event           = l_event

     im_objkey          = l_objkey

     im_event_container = l_event_container

   RECEIVING

     re_event           = l_event_ref.

 

*-----------------------------------------------------------------------

*       RAISE

*-----------------------------------------------------------------------

TRY.

*   Refresh the buffers

     cl_swf_evt_services=>reset_buffers( ).

 

* Trigger the event

     CALL METHOD l_event_ref->raise.

 

   CATCH cx_root INTO lex_root. " should never occur

     IF lex_root IS BOUND.

       l_string = lex_root->get_text( ).

       MESSAGE l_string TYPE 'I'.

     ENDIF.

ENDTRY.

 

COMMIT WORK.


Viewing all articles
Browse latest Browse all 3160

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>