cancel
Showing results for 
Search instead for 
Did you mean: 

ABAP Event Create

syed_ahmed
Discoverer
0 Kudos

Dear Experts,

I am new to workflow.

I am triggering BUS2017 Event through BADI and using function module "SAP_WAPI_CREATE_EVENT"

As you can see there are event parameters of MSEG and MKPF in BUS2017 object.

When i pass the MKPF parameter through SWUE its working fine and parameter is passed.

But when using "SAP_WAPI_CREATE_EVENT" , as input container is element - value pair , I am unable to pass

MSEG and MKPF values there.

Can any one guide please how to pass structured or tabled type values in sap_wapi_create_event as parameter of event,

Accepted Solutions (1)

Accepted Solutions (1)

StephaneBailleu
Active Contributor

Hi

Or use the more modern form with class

I made a quick and dirty test

REPORT z_bus2017_test.
CONSTANTS :
lc_typeid TYPE swrsibfti VALUE 'BUS2017',
lc_event TYPE sibfevent VALUE 'CREATED'.

DATA :
lo_event_parameters TYPE REF TO if_swf_ifs_parameter_container,
lv_param_name TYPE swfdname.
DATA : ls_mkpf TYPE mkpf,
ls_mseg TYPE mseg,
lt_mseg TYPE TABLE OF mseg,
ls_key TYPE sibfinstid.

SELECT SINGLE * FROM mkpf INTO ls_mkpf
WHERE mblnr EQ '4900000210'
AND mjahr EQ '2022'.
CONCATENATE ls_mkpf-mblnr ls_mkpf-mjahr INTO ls_key.

SELECT SINGLE * FROM mseg INTO ls_mseg
WHERE mblnr EQ '4900000210'
AND mjahr EQ '2022'
AND zeile = 1 .
APPEND ls_mseg TO lt_mseg.

"instanciate empty event container
CALL METHOD cl_swf_evt_event=>get_event_container
EXPORTING
im_objcateg = cl_swf_evt_event=>mc_objcateg_bor
im_objtype = lc_typeid
im_event = lc_event
RECEIVING
re_reference = lo_event_parameters.

"declaration of the container
TRY.
CALL METHOD lo_event_parameters->set
EXPORTING
name = 'MSEG'
value = lt_mseg
* UNIT =
* IMPORTING
* RETURNCODE =
.

CALL METHOD lo_event_parameters->set
EXPORTING
name = 'MKPF'
value = ls_mkpf
* UNIT =
* IMPORTING
* RETURNCODE =
.

CATCH cx_swf_cnt_cont_access_denied .
CATCH cx_swf_cnt_elem_access_denied .
CATCH cx_swf_cnt_elem_not_found .
CATCH cx_swf_cnt_elem_type_conflict .
CATCH cx_swf_cnt_unit_type_conflict .
CATCH cx_swf_cnt_elem_def_invalid .
CATCH cx_swf_cnt_container .
ENDTRY.


"Raise the event
TRY.
CALL METHOD cl_swf_evt_event=>raise
EXPORTING
im_objcateg = cl_swf_evt_event=>mc_objcateg_bor
im_objtype = lc_typeid
im_event = lc_event
im_objkey = ls_key
im_event_container = lo_event_parameters
.
CATCH cx_swf_evt_invalid_objtype .
CATCH cx_swf_evt_invalid_event .
ENDTRY.

COMMIT WORK. .

syed_ahmed
Discoverer
0 Kudos

Thanks Alot. It Solved my problem.

Regards

Answers (1)

Answers (1)

DominikTylczyn
Active Contributor

Hello syed_ahmed

I did a little debugging for you. It looks like SAP_WAPI_CREATE_EVENT is not able to handle non-character like structures in event containers. The actual check is done in the CL_SWF_IO_SERVICES->CHECK_STRUCTURE method:

       CALL METHOD cl_swf_exp_service=>struct_is_charlike
        EXPORTING
          structure_ref       = l_dref
        IMPORTING
          is_charlike         = l_is_charlike
          initial_char_string = l_init_string
          num_char_components = l_num_char_comp.
      IF l_is_charlike IS INITIAL.
****    Error, this structure is not character-like. It cannot
****    be initialized via a string.
        msg_error '120'  im_type_name space space space.
        EXIT.
      ELSE.

You can put a break-point there and check who it is handled in your call to SAP_WAPI_CREATE_EVENT_EXTENDED.

It's a shame though that this problem is not propagated back to SAP_WAPI_CREATE_EVENT log.

At the same time you can create the event and specify its container in SWUE as SWUE does not use SAP_WAPI_CREATE_EVENT. The limitation comes from SAP_WAPI_CREATE_EVENT implementation, not from the event itself.

I guess you have the following options:

  1. Raise a ticket to SAP support about the problem. Honestly, there is little chance that it will be fixed.
  2. Try sandra.rossi suggestion and pass the container with IFS_XML_CONTAINER
  3. Don't use SAP_WAPI_CREATE_EVENT and create the event directly with CL_SWF_EVT_EVENT class.

I would suggest the last approach.

Best regards

Dominik Tylczynski

Sandra_Rossi
Active Contributor

Nice catch!

Sandra_Rossi
Active Contributor

But the OP says it works fine through SWUE, so there should be a way to pass the parameters.

Maybe via parameter IFS_XML_CONTAINER?

syed_ahmed
Discoverer
0 Kudos

Ya im able to pass as you can see in below images

I m passing MKPF values here,

and in event trace , i am getting values as i passed here

DominikTylczyn
Active Contributor
0 Kudos

syed_ahmed See my updated answer.

syed_ahmed
Discoverer

Thank you ! Trying this will update when done