/AIF/ERR Archives - INT4 Your soft landing in SAP API testing Tue, 20 Oct 2020 12:38:57 +0000 en-GB hourly 1 https://wordpress.org/?v=6.0.8 How to save content of the outbound synchronous proxy interface in SAP AIF? https://test11988.futurehost.pl/save-content-outbound-synchronous-proxy-sap-aif Mon, 24 Sep 2018 09:02:29 +0000 https://www.int4.com/?p=1903 Have you ever struggled with payload of the outbound proxy response in SAP AIF? We've got a solution!

The post How to save content of the outbound synchronous proxy interface in SAP AIF? appeared first on INT4.

]]>

Introduction

Recently, during my last AIF project, we encountered a challenge and we wondered if it is possible to save the payload of the response message for the outbound synchronous proxy interface in SAP AIF. We found a solution, but since that time many of our colleagues working with SAP AIF encountered the same challenge and that was the reason why we decided to write this blog with our proposed solution. This blog is written in cooperation with my colleague, Krzysztof Łuka.

Problem Description

Imagine the situation when you have to configure the outbound synchronous proxy interface in SAP AIF and you have to save the content of the request and the response messages. If it comes to the content of the request message – there is no problem. You may encounter a challenge if you want to save also the response of the synchronous message.

Example

In this blog we will focus only on the SAP AIF part – we won’t describe how to create objects on SAP PO side. We will use the ABAP report to send the request message with the message ID from ERP system to SAP PO. We expect to receive back in the synchronous response the SAP PO message key that is related to the message ID we sent in the request.

This is how sample synchronous request message looks like (with the message ID):

SAP AIF - proxy message request

And below you can see the synchronous response message with message key from the above request:

SAP AIF - proxy message response

 

Step by Step Instruction

First, you have to generate and activate Service Consumer that will be used in order to send the request from ERP to SAP PO.

Then you have to copy the name of the class for the generated Service Consumer. In our case, it is /INT4/CO_SI_O_GET_MESSAGE_LIST.

SAP AIF - proxy class name for processing

This class is necessary in order to create SAP AIF interface.

In next step go to AIF Customization ( /AIF/CUST transaction ) and go to Interface Development -> Define Interfaces. We will have to create new entries: one interface for the request message and the second interface for the response message.

First, create a new entry for the request message.  Type OPRGMSG001 as the interface name and 1 as the interface version.

Then Provide your Service Consumer class (in our case it’s /INT4/CO_SI_O_GET_MESSAGE_LIST ) in the class Proxy Class Outbound field and choose the proper method that will trigger sending a message to PO.

Once you provide proxy class outbound – automatically RAW Data Structure and Record Type in Raw Structure should be filled. Please provide the same structure in SAP Data Structure as was filled into RAW Data Structure and mark Move Corresponding Structures checkbox, as it is visible on the screen below:

 Outbound SAP AIF Interface determination

As a next step, we have to create another entry in Define Interface node. This time we have to do it for the Response Message.

Add a new entry with Interface Name: IPRGMSG001, interface version: 1. In Proxy Class Inbound provide the class of your Service Consumer. In our case, it is /INT4/CO_SI_O_GET_MESSAGE_LIST. Then click enter and again your Raw Data Structure should be filled automatically. Right now we are interested in the response message and because of this, we have to provide the type of the structure that is used as the exporting parameter of our class for the service consumer. In our case it is /INT4/MT_GET_MSG_LIST_RES as it’s visible on the screen below:

 SAP-AIF-outbound-synchronous-message

Use the same structure in SAP and RAW structure and mark Move Corresponding checkbox.  Please also make sure, that you have chosen specific proxy method as shown on the screen below:

Outbound SAP AIF interface definition - response

Right now we have to make sure, that proper Engine is used for both of our interfaces. Go to AIF Customization (transaction /AIF/CUST ). Then open Interface Development -> Additional Interface Properties -> Specify Interface Engines node and set for both interfaces Proxy as Application Engine, XML as Persistence Engine, AIF Index Tables as Selection Engine and AIF Application Log as Logging Engine.

SAP-AIF-Interface-Engines

The last step is to create ABAP Report, that will trigger sending the message from ERP to SAP PO.

Create a new program in transaction SE38.
In order to make this program simpler – we will hardcode the message ID that will be sent to SAP PO. We are using function module /AIF/SEND_WITH_PROXY to send the data out from ERP. We have to provide a namespace, interface name and interface version of our interface we created in AIF. In this step, you have to provide an interface used for the request message ( ‘OPRGMSG001’).

In the RESP_SAP_STRUCT changing parameter we have to provide a structure of the response, that we used in the IPRMSG001 SAP AIF interface. Then in the SAP_STRUCT changing parameter, we have to provide filled with the data structure for the request interface.

In the end, we have to use method /AIF/IF_PERSISTENCY_ENGINE~UPDATE of class /aif/cl_persist_engine_xml in order to store the response payload in SAP AIF. While using this method we have to provide details of the second interface in SAP AIF, that will store the response message.

Please see the whole code snippet for this program below:

<em>CONSTANTS:</em>
<em>  lc_ns          TYPE /aif/ns        VALUE 'ZDEMO',</em>
<em>  lc_ifname      TYPE /aif/ifname    VALUE 'OPRGMSG001',</em>
<em>  lc_ifver       TYPE /aif/ifversion VALUE '1',</em>
<em>  lc_ns_resp     TYPE /aif/ns        VALUE 'ZDEMO',</em>
<em>  lc_ifname_resp TYPE /aif/ifname    VALUE '1PRGMSG001',</em>
<em>  lc_ifver_resp  TYPE /aif/ifversion VALUE '1'.</em>

<em>DATA:</em>
<em>  lv_msguid      TYPE sxmsmguid,</em>
<em>  lv_error_msg   TYPE string,</em>
<em>  ls_request     TYPE /int4/mt_get_msg_list_req,</em>
<em>  ls_sap_resp    TYPE /int4/mt_get_msg_list_res,</em>
<em>  ls_xi_data     TYPE /aif/xmlparse_data,</em>
<em>  lt_bapiret     TYPE TABLE OF bapiret2,</em>
<em>  lo_data        TYPE REF TO data,</em>
<em>  lo_xml_pers    TYPE REF TO /aif/cl_persist_engine_xml.</em>

<em>ls_request-mt_get_msg_list_req-message_id = 'fd9b26f7-7456-11e8-a1b1-00000069c71a'.</em>
<em>ls_request-mt_get_msg_list_req-archive = ' '.</em>

<em>IF ls_request-mt_get_msg_list_req-message_id IS NOT INITIAL.</em>
<em>  CALL FUNCTION '/AIF/SEND_WITH_PROXY'</em>
<em>    EXPORTING</em>
<em>      ns                   = lc_ns</em>
<em>      ifname               = lc_ifname</em>
<em>      ifversion            = lc_ifver</em>
<em>      appl_log_function    = 'AIF_SEND_WITH_PROXY'</em>
<em>      do_commit            = 'X'</em>
<em>      iv_persist_xml       = 'X'</em>
<em>    IMPORTING</em>
<em>      ximsgguid            = lv_msguid</em>
<em>    TABLES</em>
<em>      add_return_tab       = lt_bapiret</em>
<em>    CHANGING</em>
<em>      resp_sap_struct      = ls_sap_resp</em>
<em>      sap_struct           = ls_request</em>
<em>      error_string         = lv_error_msg</em>
<em>    EXCEPTIONS</em>
<em>      persistency_error    = 1</em>
<em>      status_update_failed = 2</em>
<em>      missing_keys         = 3</em>
<em>      interface_not_found  = 4</em>
<em>      transformation_error = 5</em>
<em>      general_error        = 6</em>
<em>      OTHERS               = 7.</em>

<em>ENDIF.</em>

<em>"Persist response message</em>
<em>GET REFERENCE OF ls_sap_resp INTO ls_xi_data-xi_data.</em>
<em>ls_xi_data-msgguid = lv_msguid.</em>
<em>ls_xi_data-ns = lc_ns_resp.</em>
<em>ls_xi_data-ifname = lc_ifname_resp.</em>
<em>ls_xi_data-ifver = lc_ifver_resp.</em>
<em>CREATE OBJECT lo_xml_pers.</em>
<em>IF lo_xml_pers IS NOT INITIAL.</em>
<em>  GET REFERENCE OF ls_xi_data INTO lo_data.</em>
<em>  TRY.</em>
<em>      CALL METHOD lo_xml_pers-&gt;/aif/if_persistency_engine~update</em>
<em>        CHANGING</em>
<em>          cr_xmlparse = lo_data.</em>
<em>    CATCH /aif/cx_error_handling_general .</em>

<em>  ENDTRY.</em>
<em>ENDIF.

</em>

Right now we can run the report. If the proxy call was successful we should see a new entry in transaction /AIF/ERR with the payload in the outbound interface OPRGMSG001 with the request message and new entry in with the payload of the response message in interface IPRGMSG001.

Below you can see the request message with the content. Message text automatically contains the information in which interface the response was processed:

SAP-AIF-Proxy-Interface-Request-Message

In order to make sure that the response is visible we’ll go to the second interface for the response message. As you can see on the screenshot below – response message with the payload is there:

SAP AIF Synchronous outbound message- content

How do you like this approach to save the message payload? Please let us know in the comments!

PS. I have a big pleasure to invite you on SAP Teched at Barcelona that will take place in October. As the Int4 team we will be one of the exhibitors and we will be presenting our SAP certified automated regression testing and service interface virtualization software –  Int4 IFTT.

SAP Teched 2018 in Barcelona

If you want to learn more about this tool or if you want to ask me or Michal Krawczyk SAP AIF or SAP PO related question we will be available  for you at our booth everyday from 13:00-14:00 everyday! See you there!

The post How to save content of the outbound synchronous proxy interface in SAP AIF? appeared first on INT4.

]]>