File to Inbound Proxy Scenario SAP PI/PO Single Stack

This article illustrates the complete file to inbound Proxy interface development in detail. In addition, we will look at how to generate Proxy class in SAP back-end and implement ABAP logic. File to Proxy interface scenario is illustrated using an SAP exchange rate creation asynchronous interface. Exchange rates included in the XML file are sent to SAP via a Proxy message. Once exchange rates are received in SAP, TCURR table will be updated from BAPI.

Inbound Proxy Scenario Overview:

Let’s assume we have an sFTP file system that sends exchange rates in XML format. Exchange rates in XML file should be extracted, transformed and sent to target SAP system via SAP PI/PO.

Information is sent to SAP system as a Proxy message and exchange rates should be updated in SAP table TCURR (Exchange Rates). However, we will use BAPI ‘BAPI_EXCHANGERATE_CREATE’ to update the exchange rates table TCURR as it’s the preferred best practice.

Interface Flow Overview:

XML file (sFTP) to SAP Proxy Inbound Interface Example Overview in detail
XML file (sFTP) to SAP Proxy Inbound Interface Example Overview.

Sender File (XML) Format:

Receiver Proxy Format:

XML File to Proxy Message Mapping

Mapping logic between the XML file sender message and target proxy message is as follows.

Proxy Target Element
Transformation/Mapping LogicXML Source Element
RATE_TYPE Constant ‘M’
FROM_CURR ExchangeRates/Rates/FromCurrency
TO_CURRNCY ExchangeRates/Rates/ToCurrency
VALID_FROM Convert MM-dd-yyyy to yyyy-MM-ddExchangeRates/Rates/ValidFromDate
EXCH_RATE ExchangeRates/Rates/ExchangeRate
FROM_FACTOR Constant ‘1’
TO_FACTOR Constant ‘1’
EXCH_RATE_V Constant ‘0.0’
FROM_FACTOR_V Constant ‘0’
TO_FACTOR_V Constant ‘0’

Functionality of the Proxy Class:

ABAP Proxy class update the SAP exchange rates table TCURR using ‘BAPI_EXCHANGERATE_CREATE‘. In addition, proxy ABAP logic assigns the exchange rate values from the proxy message to the BAPI input parameter.

BAPI accepts the exchange rates through importing parameter EXCH_RATE. ABAP logic assigns the exchange rates in the proxy message to EXCH_RATE parameter of the BAPI_EXCHANGERATE_CREATE.

Import parameters of BAPI_EXCHANGERATE_CREATE. We will use import parameter set exch_rate in this example to import the changes rates.
Import parameters of BAPI_EXCHANGERATE_CREATE
DDIC data type of Exch_rate parameter of the BAPI
DDIC data type of Exch_rate parameter of the BAPI

File to Proxy Interface Development Steps:

  1. Configure Proxy connectivity between SAP PI/PO and SAP back-end system.
  2. Create sender XML Data Type and Message Type.
  3. Create receiver Proxy Data Type and Message Type.
  4. Define Outbound file Service Interface and Inbound Proxy Service Interface.
  5. Implement Message Mapping between XML and Proxy message.
  6. Generate Proxy class in SAP back-end using transaction SPROXY.
  7. Create sFTP sender Communication Channel and Proxy (SOAP) receiver Channel.
  8. Finally, configure iFlow using Eclipse NWDS.

Step 1 – Configure Proxy Connectivity Between SAP PI/PO and SAP Back-end System:

The first step is to set up Proxy connectivity. Follow my complete step-by-step guide on how to configure proxy connection between ECC and SAP PI/PO.

You will find information on SLD setup, RFC destination configuration, HTTP Destination configuration, Integration Engine (SXMB_ADM) settings, and Proxy Communication Channel configuration in my previous post. Therefore, I will not elaborate on the steps in this example.

Step 2 – Create Sender XML Data Type and Message Type:

Next step is to create the exchange rate sender Data Type and Message Type in Enterprise Service Repository (ESR). You can either create the Message Type as an External Definition by importing the XSD or by creating a Data Type which reflects the XML data structure.

In this illustration, I have created a Data Type and Message Type to represent the exchange rate sender XML message format.

Sender Data Type:

Source Data Type for XML exchange rate sender message created in ESR
Source Data Type for XML exchange rate sender message

Sender Message Type:

Input Message Type for XML exchange rate sender message in ESR
Input Message Type for XML exchange rate sender message

Step 3 – Create Receiver Proxy Data Type and Message Type:

The function of the Proxy is to update exchange rates in SAP using the Function Module BAPI_EXCHANGERATE_CREATE. Therefore, we will create the target Proxy Message Type to closely reflect the import parameters of the BAPI.

To update the exchanges rates we need to assign values from Proxy message to input parameter EXCH_RATE of the BAPI. Create the receiver Message Type similar to the structure of EXCH_RATE Data Type. In other words, Data Type should be similar to DDIC structure BAPI1093_0.

Designing the Message Type like this allows us to easily move data from the proxy message to the BAPI using MOVE-CORRESPONDING ABAP statement.

Receiver Data Type:

Receiver Date Type for Proxy message in ESR
Receiver Date Type for Proxy message

Receiver Message Type:

Receiver Message Type for Proxy message in ESR
Receiver Message Type for Proxy message

Step 4 – Define Outbound file Service Interface and Inbound Proxy Service Interface:

Create an Outbound Service interface for XML file sender and an Inbound Service Interface to represent the Proxy message. As we have only one operation, let’s use Interface Pattern Stateless (XI30 Compatible) for both interfaces.

Outbound Asynchronous Service Interface:

Outbound Asynchronous Service Interface for exchange rates sender with interface pattern Stateless XI30 Compatible and only one operation
Outbound Asynchronous Service Interface for exchange rates sender

Inbound Asynchronous Proxy Interface:

Inbound Asynchronous Service Interface for exchange rates proxy receiver with interface pattern Stateless XI30 Compatible and only one operation
Inbound Asynchronous Service Interface for exchange rates receiver

Step 5 – Implement the Message Mapping between the XML file and the Proxy message:

Next, define the Message Mapping and the Operation mapping.

Operation and Message Mapping:

Message Mapping and Operation Mapping on file to proxy exchange rates scenario
Message Mapping and Operation Mapping

Create the Message Mapping from the XML file Message Type to the Proxy Message Type. Most importantly, apart from the date conversion between sender message ‘ValidFromDate’ element and receiver message ‘VALID_FROM’ element, all the other fields are mapped one-to-one or mapped with constant values.

Message Mapping:

Message Mapping from XML to Proxy message type in ESR. With mapped fields shown
Message Mapping from XML to Proxy message type

Date Transformation using DateTrans Function:

XML contains the date in format MM-DD-YYYY, and it should be converted to SAP Proxy date format YYYY-MM-DD. SAP accepts the date in YYYYMMDD
conversion. Sender date format should be converted in the Mapping program.

Standard PI mapping function DateTrans allows us to convert date formats.

Date transformation using graphical mapping function DateTrans. Input date format MM-dd-yyyy output date format yyyy-MM-dd
Date transformation using graphical mapping function DateTrans

Operation Mapping:

Operation Mapping 'ExchangeRates_to_ExchangeRates'.
Operation Mapping ‘ExchangeRates_to_ExchangeRates’.

Step 6 – Generate Proxy Class in SAP Back-end Using Transaction SPROXY:

Now we need to generate Proxy Consumer class in SAP back-end system.

Go to transaction SPROXY in target SAP system (SADCLNT900) and find the Proxy Service Interface from the ESR navigation tree.

Next, right-click on the Service Interface and click Generate. Proxy generation wizard will guide you through the proxy class creation.

Right click on Service Provider interface and select generate to create the proxy class using the proxy generation in SPROXY
Right-click on Service Provider interface and select generate in SPROXY transaction

In the next screen of the wizard, you will be prompted to assign a Package, Prefix and Transport request for the new Proxy class. Fill in the required information in the wizard, save and activate the Proxy class.

Proxy Class generation Wizard. Assign the Package, Transport Request and Prefix.
Proxy Class generation Wizard. Assign the Package, Transport Request and Prefix.

Successfully generated and activated Proxy Service Interface (Proxy ABAP class) will be visible in SPROXY transaction with a green mark as below.

Service Provider proxy object in SPROXY transaction. Proxy class generated.
Service Provider proxy object in SPROXY transaction

Using Proxy Services external view tab, we can check the Proxy Inbound data type. Notice, this correlates to the Receiver Message Type we created in Step 3. Message Types and Data Types we created in ESR are automatically generated as DDIC structures in SAP when the Proxy class is created using SPROXY transaction.

In this example, the Proxy Implementing Class name is ZCL_EXCHANGE_RATES_INB_ASYNC. It has one method, which is ZII_EXCHANGE_RATES_INB_ASYNC~EXCHANGE_RATES_INB_ASYNC. ABAP logic to execute the exchange rate creation BAPI should be implemented here.

Access the Proxy Implementing Class via SPROXY transaction. From the Service Provider Interface access the Proxy Class to implement the ABAP logic.
Access the Proxy Implementing Class via SPROXY transaction.

Implement ABAP logic to Update Exchange Rates in SAP:

Finally, implement ABAP logic in Proxy class to update the exchange rates in SAP. ABAP logic reads the incoming proxy message (parameter INPUT) and assigns the values to import parameter EXCH_RATE of FM BAPI_EXCHANGERATE_CREATE.

Double-click on the Implementing Proxy class in transaction SPROXY and it will take you to the method EXCHANGE_RATES_INB_ASYNC in which you need to implement ABAP code. Or you can implement ABAP code via transaction se24.

Next, implement ABAP program logic in Proxy class which updates exchange rates in SAP.

Proxy Class Signature and ABAP Code to update Exchange Rates in SAP
Proxy Class Signature and ABAP Code to update Exchange Rates in SAP

Step 7 – Create sFTP Sender Communication Channel and Proxy (SOAP) Receiver Channel:

Let’s create sender and receiver Communication Channels.

We require one File Adapter sender Communication Channel with protocol sFTP. Sender Communication Channel should be created under the sender Business System Test A.

Proxy Receiver Communication Channel:

Similarly, we need a Communication Channel for Proxy Receiver. Adapter type of Proxy receiver Channel is SOAP and Transport Protocol is HTTP with Message Protocol XI 3.0.

SOAP Adapter General Configuration:

SOAP Receiver General Configuration. Adapter type SOAP, Transport Protocol HTTP and Message Protocol XI 3.0
SOAP Receiver General Configuration

Receiver Proxy Channel should be created under SAP back-end system Business System.

SOAP Adapter Specific Configuration:

HTTP destination pointed at SAP back-end system is created in Netweaver Development Administration (NWA). The destination should be assigned to the Communication Channel.

SOAP Receiver Communication Channel Adapter Specific Attributes and configuration. HTTP destination configured
SOAP Receiver Communication Channel

Step 8 – Generate the iFlow Using NWDS:

Last step of the interface development configuration is to setup the iFlow.

Exchange rate sender system is Test A and receiver system is SADCLNT900. The exchange rates mapping program we created in Step 5 is ExchangeRates_to_ExchangeRates.

Receiver Proxy SOAP Communication Channel is SOAP_Reliever. We created the Channels in Step 7.

Using these objects, define the iFlow using Eclipse NWDS. You can also complete the Integration Directory configuration using the Integrated Configuration Object (ICO).

File to Proxy iFlow. Sender system Test_A to SAP client SADCLNT900.
File to Proxy iFlow

Test the Inbound Proxy Interface:

Here we will test the complete interface end to end.

Test Interface using PI Test Tool:

First, let’s test the interface using SAP PI AFW Test Tool. This will help us to find out if there are any issues in the Message Mapping program or Proxy ABAP logic.

Send a Test Message using PI Test Tool:

Go to Test Tool from the Monitoring home.

Select the Integrated Configuration Object (ICO) and choose the Quality of Service. Next, paste the XML payload content and click ‘Send’ button to process the message.

Note down the message ID. It’s easy to find the proxy message in SAP using message ID.

Monitor the Interface from PI to SAP:

Monitor the message via PI message monitor.

Using Advance Selection Criteria in transaction SXMB_MONI, we can select the proxy message using the message ID we noted down previously.

Proxy XML message content can be monitored in SXMB_MONI message viewer.

Go to transaction se16n to check if exchange rates are updated as expected.

If you have any questions on the steps illustrated or Proxy Inbound interfaces, please leave a comment below!

Get the latest tips and tricks on SAP!

Add a Comment

Your email address will not be published. Required fields are marked *