Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

Quite often I have to deal with reports that list some documents and from where the user can start other business processes by sending a message via PI. The information available in the payload might require some complex calculations. As a user, wouldn't it be interesting to have a message preview before actually sending such a message?

The following screenshots shows an example:

Here the user can choose a line and decide between sending the message or just making a preview.

A preview is just a popup with the XML but no message is actually sent.

This has turned out to be quite useful for the key users in production but also for the development team while testing.

How to do it? You just need to calculate the message payload and then, instead of calling the proxy, you need to transform the abap structure into an XML and finally display it.  Something like this where <fs_rmb_msg> contains the same structure as when calling the proxy.

Method map_payload_from_proxy handles the conversion between ABAP and XML and is generic enough to support any message format. You just need to pass the name of your interface and the method. SAP creates automatically an XSLT for each proxy that converts back and forward between XML<->ABAP so this method just need to find the XSLT and execute it. The following code shows how to do it:

class-methods MAP_PAYLOAD_FROM_PROXY

    importing

      !IV_PROXY_CLASS type PRX_R3NAME

      !IV_PROXY_METHOD type PRX_R3NAME

      !IS_PAYLOAD type ANY

    returning

      value(RV_XML_STRING) type STRING

    raising

      CX_XMS_SYSTEM_ERROR

      ZCX_GU_PI_MSG .

  METHOD map_payload_from_proxy.

    DATA : lr_request TYPE REF TO if_sxmlp_data_st.

    DATA : lr_root TYPE REF TO cx_root.

    DATA : lr_payload TYPE REF TO if_ws_payload.

    DATA : lr_payload_data TYPE REF TO data.

    DATA: lt_bindings TYPE abap_trans_resbind_tab,

          ls_binding  TYPE abap_trans_resbind.

* ---------- Check mandatory parameters -----------------------------------------------------------

    mandatory_param_generic iv_proxy_class  'IV_PROXY_CLASS'.

    mandatory_param_generic iv_proxy_method 'IV_PROXY_METHOD'.

    mandatory_param_generic is_payload 'IS_PAYLOAD'.

    TRY .

        cl_proxy_st_part=>create_for_clas_method( EXPORTING class         = iv_proxy_class

                                                                                                   method        = iv_proxy_method

                                              IMPORTING request_part = lr_request ).

        CLEAR ls_binding.

             ls_binding-name  = 'OUTPUT'.

        GET REFERENCE OF is_payload INTO lr_payload_data.

             ls_binding-value = lr_payload_data.

        APPEND ls_binding TO lt_bindings.

             lr_payload = serialize( part     = lr_request

                                                        bindings = lt_bindings ).

             rv_xml_string = lr_payload->get_xml_text( ).

      CATCH cx_root INTO lr_root.

                  RAISE EXCEPTION TYPE zcx_gu_pi_msg

                    EXPORTING

                      textid   = zcx_gu_pi_msg=>conversion_error

                      previous = lr_root.

    ENDTRY.

ENDMETHOD.


where method serialize is a local copy of method CL_WS_PAYLOAD_HANDLER=>serialize.



2 Comments
Labels in this area