Passing multiline parameters from an ABAP Class event to a Workflow container

...Previous

Now, we need the ABAP code for raising the event (and for passing parameters).

REPORT  ytrigger_multiline.

* Data Declarations
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 pa0001-ename.

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

 

Finally, we can test our code.

And then, we review the workflow log, and data within the workflow container looks like this.

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