cancel
Showing results for 
Search instead for 
Did you mean: 

How to create multiple files with Receiver File Adapter in SAP PI 7.31 Java Stack

Former Member
0 Kudos

Dear Friends,

I am using Sender JDBC Adapter and Receiver File Adapter in Integration Flow in SAP PI 7.3 EHP 1 SP08 Java Stack environment. The requirement is that we need to create multiple files based on the row count in jdbc resultset. If there are 5 rows in resultset, we need to create 5 XML files with one row elements in one file. Similarly if there are 10 rows, we need to create 10 XML files.

So how can we create multiple files in this scenario. I tried placing a for loop in the Java Mapping as below in the transform method:

DynamicConfiguration conf = arg0.getDynamicConfiguration();

StringBuffer sbFileData = new StringBuffer();

for (int i =0; i < record.size(); i++ {

     .

     .

     . // Create XML for each row and Marshal the object into to the String Buffer

     String strFileName = "DC_" + new SimpleDateFormat("ddMMyyyyHHmm").format(new java.util.Date())+"_"+i+".xml";

     conf.put(KEY_FILENAME, strFileName);

     arg1.getOutputPayload().getOutputStream().write(sbFileData.toString().getBytes("UTF-8"));

     arg1.getOutputPayload().getOutputStream().flush();

}

So here I'm flushing the OutputStream for each record. But it's not creating the multiple file, instead it creates only one file will all record XMLs appended to each other.

Please let me know if I missing something or need to do some thing else.

Regards,

Shreyansh Shah

Accepted Solutions (1)

Accepted Solutions (1)

Muniyappan
Active Contributor
0 Kudos

Hi,

you have to use multi mapping for this. hope this can help you.

Multi-Mapping using Java Mapping - Process Integration - SCN Wiki

Any reason why you are going for java mapping?

you can handle this in message mapping also.

Regards,

Muni.

Former Member
0 Kudos

Thanks Muniyappan, this helps!

About why we are using Java Mapping, it's already mentioned in the Reference section of article you have provided i.e. Java multi-mapping (this blog) has the advantages of Java mappings i.e., archiving complex mapping logics.

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi

You can easily achieve this using graphical mapping.  Create your target message type like below

MT_Target

  Details  0 to 1

      Data  0 to 1

Source sample structure

<resultset>

<row>

<column-name>column-value</ column-name>

</row>

Then do the message mapping like below

map <row> with  MT_Target

contant ----> Deatils

column-name ------>Data

In the signature tab of message mapping, choose the occurrence of your target message type as

0 to unbounded.

This will generate multiple files from multiple rows.

Let me know if you have any doubt.