Skip to Content
Author's profile photo Former Member

Java mapping to read a csv file attachment and convert into required XML

Summary

This document will help us in understanding and achieving the following scenario by using Java Mapping

Scenario:

  • SAP PI receives a .csv file as an attachment.
  • The attachment needs to be read ,converted in to XML and place the XML file in the target location
  • The .csv file contains multiple records with 2 fields in each record

  Note: The above scenario can be further enhanced based on the requirement.

Prerequisites

·        Java and PI Knowledge.

·        SAP PI 7.31(Single Stack), SAP NetWeaver Developer Studio 7.31 SP07, Java Version 1.6.

Details

PFA Java Mapping Code and test sample files for reference.

ESR Configuration

Source Message Type

pic1.JPG

Target Message Type

pic2.JPG

–          Create Outbound and Inbound Service Interfaces and assign these message types.

    Note: For Outbound Interface, Please choose Interface Pattern as: Stateless (XI 3.0- Compatible)

–          Import the java mapping in ESR under Imported Archives

–          Create Operation mapping and assign the java class from the imported archives as shown below:

pic3.JPG

Please check Read Attachments check box in Operation Mapping

In Integration Directory, you can configure a simple File to File scenario

Note: While configuring the sender file adapter, make sure Additional File(s) section is selected under this section you have to mention the csv file name that will be picked as an attachment or you can refer to my blog http://scn.sap.com/docs/DOC-44537 where in an customized adapter module is being used to achieve this functionality.

Sender FILE Channel Configuration

pic4.JPG

NFS location contains the following files

pic5.JPG

Sender Channel is started and the following audit logs can be seen in the Audit logs

    pic6.JPG

Message Monitoring Logs is as shown below . Here, in the below screenshot , you can see the File.csv coming as an attachment in the payload.

pic7.JPG

Following is the output of Java mapping

pic8.JPG

Assigned Tags

      2 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Hi Vinay,

      How can I do the same with FTP server.

      Author's profile photo Joe S
      Joe S

      Hi Vinay,

      I'm trying to refer your adapter module development blogs - http://scn.sap.com/docs/DOC-44536
      But looks like its not migrated yet. Would you be able to get this migrated or do you've a copy of the document for me to refer please?

      Thanks