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: 

There was a requirement to consume a RESTful web service which accepts payload data in CSV format and the data was received in SAP PI from ECC system through proxy. Data can be sent through the REST adapter in either XML or JSON format, REST adapter does not provide any other data format.

Sample CSV format:

FirstName,LastName,Email,CompanyName,ParentCompanyName

Rahul,Kumar,rahul.kumar@xyz.com,abc,xyz

Chandan,Yadav,chandan.yadav@xyz.com,abc,xyz

In order to send data in a format other than XML or JSON through REST adapter we followed the below steps:

1)      Conversion of XML data to CSV

For converting the data from XML to CSV format we used the Message Transformation Bean

Sample XML data in which was received in SAP Pi from ECC:


<?xml version="1.0" encoding="UTF-8"?>
<CustomerData>
                <CustomerDetails>
                                <FirstName>FirstName</FirstName>
                                <LastName>LastName</LastName>
                                <Email>Email</Email>
                                <CompanyName>CompanyName</CompanyName>
                                <ParentCompanyName>ParentCompanyName</ParentCompanyName>
                </CustomerDetails>
                <CustomerDetails>
                                <FirstName>Rahul</FirstName>
                                <LastName>Kumar</LastName>
                                <Email>rahul.kumar@xyz.com</Email>
                                <CompanyName>abc</CompanyName>
                                <ParentCompanyName>xyz</ParentCompanyName>
                </CustomerDetails>
                <CustomerDetails>
                                <FirstName>Chandan</FirstName>
                                <LastName>Yadav</LastName>
                                <Email>chandan.yadav@xyz.com</Email>
                                <CompanyName>abc</CompanyName>
                                <ParentCompanyName>xyz</ParentCompanyName>
                </CustomerDetails>
</CustomerData>

We used the following settings for MTB for converting XML to CSV:

Module KeyParameter NameParameter Value
xmltocsvTransform.Classcom.sap.aii.messaging.adapter.Conversion
xmltocsvTransform.ContentTypeapplication/json;charset=utf-8
xmltocsvxml.CustomerDetails.endSeparator'nl'
xmltocsvxml.CustomerDetails.fieldSeparator,
xmltocsvxml.conversionTypeStructXML2Plain
xmltocsvxml.recordsetStructureCustomerDetails

Note : The content type was set to application/json in order to send the CSV data in the JSON format

2)      REST channel configuration for setting the Data Format

As the default data conversion of REST adapter was not required so we used the following settings to send the CSV data:

Set the Data Format as “JSON” and Character Set Name as “UTF-8”.

The “Convert XML Payload to JSON” and “Strip Operation from Message (Outer Element)” options need to be unchecked so that REST adapter does not transform the data.

5 Comments
Labels in this area