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.
Additionally, you can also refer my articles on Outbound ABAP Proxy and functionality of Fault Messages for Inbound ABAP Proxy interfaces.
SAP Versions used in the illustration:
- SAP S4 HANA Fashion 1709
- SAP PO 7.5
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:
Sender File (XML) Format:
<?xml version="1.0" encoding="UTF-8"?> <ns0:ExchangeRates xmlns:ns0="urn:Source_System:ExchangeRates"> <Rates> <FromCurrency>USD</FromCurrency> <ToCurrency>EUR</ToCurrency> <ExchangeRate>0.1</ExchangeRate> <ValidFromDate>01-03-2019</ValidFromDate> </Rates> </ns0:ExchangeRates>
Receiver Proxy Format:
<?xml version="1.0" encoding="UTF-8"?> <ns1:ExchangeRates xmlns:ns1="urn:Target_System:ExchangeRates"> <EXCH_RATE> <RATE_TYPE>M</RATE_TYPE> <FROM_CURR>USD</FROM_CURR> <TO_CURRNCY>EUR</TO_CURRNCY> <VALID_FROM>2019-01-03</VALID_FROM> <EXCH_RATE>0.1</EXCH_RATE> <FROM_FACTOR>1</FROM_FACTOR> <TO_FACTOR>1</TO_FACTOR> <EXCH_RATE_V>0.0</EXCH_RATE_V> <FROM_FACTOR_V>0</FROM_FACTOR_V> <TO_FACTOR_V>0</TO_FACTOR_V> </EXCH_RATE> </ns1:ExchangeRates>
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 Logic | XML 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-dd | ExchangeRates/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.
File to Proxy Interface Development Steps:
- Configure Proxy connectivity between SAP PI/PO and SAP back-end system.
- Create sender XML Data Type and Message Type.
- Create receiver Proxy Data Type and Message Type.
- Define Outbound file Service Interface and Inbound Proxy Service Interface.
- Implement Message Mapping between XML and Proxy message.
- Generate Proxy class in SAP back-end using transaction SPROXY.
- Create sFTP sender Communication Channel and Proxy (SOAP) receiver Channel.
- 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:
Sender Message Type:
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 Message Type:
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:
Inbound Asynchronous Proxy Interface:
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:
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:
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.
Operation Mapping:
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.
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.
Successfully generated and activated Proxy Service Interface (Proxy ABAP class) will be visible in SPROXY transaction with a green mark as below.
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.
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.
METHOD zii_exchange_rates_inb_async~exchange_rates_inb_async. *** **** INSERT IMPLEMENTATION HERE **** *** DATA: lwa_exch_rate type bapi1093_0, lwa_input LIKE LINE OF input-exchange_rates-exch_rate. *Loop data records of in coming proxy message LOOP AT input-exchange_rates-exch_rate INTO lwa_input. CLEAR lwa_exch_rate. *Move data from proxy message to local variable. MOVE-CORRESPONDING lwa_input TO lwa_exch_rate. *Execute BAPI which update the exchange rates CALL FUNCTION 'BAPI_EXCHANGERATE_CREATE' EXPORTING exch_rate = lwa_exch_rate upd_allow = 'X'. ENDLOOP. *Commit to database COMMIT WORK. ENDMETHOD.
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:
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.
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).
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.
Use either SPROXY session debugging or external debugging if the behavior of the Proxy ABAP logic needs to be analyzed at runtime.
If you have any questions on the steps illustrated or Proxy Inbound interfaces, please leave a comment below!
Bonjour,
I have a question about the Proxy Implementing Class ZCL_EXCHANGE_RATES_INB_ASYNC.
For example, if the BAPI returns an error message BAPI_EXCHANGERATE_CREATE, then how do catch it and save it ? So we can see it later in the SXMB_MONI transaction for example
BR,
Chaouki
Hello Chaouki,
You can implement fault messages to save BAPI return messages in SXMB_MONI.I have implmented this scenario in my new article about fault messages in SAP PI/PO. Additionally, you can also save BAPI return messages to SAP application log.
Cheers!
Isuru
Hi, I am new to sap po and I got a scenario where we need to migrate the pass through scenario interfaces from Informatica to sap po. And our teams says there is no ABAPer as of now. Can you please let me know, What are all the pre-requisites we need to have and also please let me know the configuration part would be really helpful.
Thanks in adavance.