Skip to Content

Write Messages to Container when calling an Exception
for an Abap Class Method

 

Add the following code into your Abap Method where you want to Raise an Exception and write messages to the
Container

 

When an error has occurred put the error messages into a table. Here I have defined a table of strings and I format the SAP messages
into it from lt_messr.

  DATA: lw_messr     TYPE eessr,
              lt_messr      TYPE TABLE OF eessr.

  DATA: lw_message   TYPE string,
              lt_message  
TYPE TABLE OF string.       

  DATA: lo_wim_handle      TYPE REF TO if_swf_run_wim_internal,
               lo_container      
TYPE REF TO if_swf_cnt_container.

* Write output messages to a table of strings

  LOOP AT lt_messr INTO lw_messr.
     MESSAGE ID   lw_messrmsgid TYPE lw_messrmsgty NUMBER lw_messrmsgno
             INTO lw_message
             WITH lw_messrmsgv1 lw_messrmsgv2 lw_messrmsgv3 lw_messrmsgv4.
     APPEND lw_message TO lt_message.
  ENDLOOP.

* write error messages to Container

TRY.
      lo_wim_handle
= cl_swf_run_wim_factory=>find_by_wiid( iv_wiid ).
      lo_container ?= lo_wim_handle
->get_wi_container( ).

      IF it_messages IS INITIAL.
     
ELSE.
        swf_set_element lo_container
‘MESSAGES’ it_messages.
        lo_container
->if_swf_utl_persistent_object~save_to_database( ).
     
ENDIF.
   
CATCH cx_swf_ifs_exception.
 
ENDTRY.

* call appropriate Exception

  RAISE EXCEPTION TYPE zcx_bo_error
   
EXPORTING
      class_name
= iv_class_name
      textid    
= zcx_bo_error=>zcx_bo_error.

Narrative

In the Task Definition, I had to pass the &_WORKITEM.WORKITEMID& from the Task Container to the Method parameter IV_WIID.
I was not able to use the Binding from the Wf Container to the Task Container, because this passes the Wf workitem, not the Task workitem.

 

I would prefer to not use the Task -> Object Binding and to leave it blank as would be defaulted, but I can’t see another simple way to get the WI Id into
the Method.

 

I use the complicated bit of Abap OO to populate a Container ‘table’ Element, it seems to be over complicated for what is basically adding a table of data to a
Container, but SAP_WAPI_SET_CONTAINER did not do it for me.

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

  1. Amarpreet Singh

    AAh ! This is god sent .

    I’d been planning on doing something like this and couldn’t think of how to achieve it.

    The Best Way would have been to some how catch the OO Exception Object reference in the Workflow and be able to play around with it by passing it around  and using its attributes / methods.

    Any idea if this is even possible. ?

    Thanks

    This blog has helped me 🙂

    Amarpreet.

    (0) 

Leave a Reply