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_messr-msgid TYPE lw_messr-msgty NUMBER lw_messr-msgno
INTO lw_message
WITH lw_messr-msgv1 lw_messr-msgv2 lw_messr-msgv3 lw_messr-msgv4.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
9 | |
9 | |
7 | |
6 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 |