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
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_messr–msgid TYPE lw_messr–msgty NUMBER lw_messr–msgno
WITH lw_messr–msgv1 lw_messr–msgv2 lw_messr–msgv3 lw_messr–msgv4.
APPEND lw_message TO lt_message.
* write error messages to Container
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.
swf_set_element lo_container ‘MESSAGES’ it_messages.
* call appropriate Exception
RAISE EXCEPTION TYPE zcx_bo_error
class_name = iv_class_name
textid = zcx_bo_error=>zcx_bo_error.
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
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.