Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

Applies to:

SAP PI developers.


According SAP PI help Link, “you can generally implement a multi-mapping with all types of mapping programs”.

Intention of this Wiki page is to point out that all types of mapping programs can be used to generate multi-mapping (1: N)..


Name: Raghu Vamseedhar Reddy .K

Company:  Infosys Limited   
Created on:    8/29/2011
Author(s) Bio
I am SAP Certified Development Associate - Process Integration with SAP Netweaver (PI 7.1). I have about 5 year experience of SAP XI/PI implementation and support.

I am also, Sun Certified Programmer for the Java Platform, Standard Edition 6. I have good understanding of XML, XSLT, SOAP, WSDL, ABAP. I am an active member in SAP SND.


PI considers a mapping (Graphical, Java, ABAP) as multi-mapping when,

  1. Mapping is able to able to generate the multi-mapping envelope, and
  2. Occurrence of service interfaces in Operational mapping is other than 1.

Each Multi-Mapping program should create following envelope:-

<?xml version="1.0" encoding="UTF-8"?>
<sm:Messages xmlns:sm="">
                <Message1> <MT_type>Payload1</MT_type> </Message1>
                <Message2> <MT_type>Payload2</MT_type> </Message2>
                <Message3> <MT_type>Payload3</MT_type> </Message3>

Note :-

  • Please pay attention to name-space it is constant and Messages -- Message1, Message2, Message3.
  • Each Message should have root XML element (it can be anything, <root> or <A> or <MT_type>). i.e., <Message1> <root>Payload1</root> </Message1>.
  • Number of messages produced by mapping should be equal to number of service interfaces which are referred in Operational mapping target side. 
  • i.e., if in Operational Mapping you have referred only one service interface then mapping should produce only Message1.

Below Java Mapping will generate this XML output:-

<?xml version="1.0" encoding="UTF-8"?>
<sm:Messages xmlns:sm="">

Java Mapping 

package com.javaMapping;


public class MultiMapping_JavaMapping extends AbstractTransformation {

    public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput) throws StreamTransformationException {
        try {
            InputStream inputstream = transformationInput.getInputPayload().getInputStream();
            OutputStream outputstream = transformationOutput.getOutputPayload().getOutputStream();

            //Getting input payload into strInContent. strInContent is not used in this example. 
            //But in your mapping, based on mapping logic it should be used.
            byte[] b = new byte[inputstream.available()];
            String strInContent = new String(b);

            //strStart and strEnd are constants.
            String strStart = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ns0:Messages xmlns:ns0=\"\">";
            //Edit according to requirement
            //Edit code to fill strMessage1 with the desired Payload1 and so on. You might need to use strInContent to construct output payload.
            String strMessage1 = "Payload1";
            String strMessage2 = "Payload2";
            String strMessage3 = "Payload3";
            String strEnd = "</ns0:Messages>";

            //Edit according to requirement.
            //Constructing the multi-mapping envelope.
            String strOutContent = strStart + "<Message1> " + "<root>" + strMessage1 + "</root>" + " <root>" + strMessage2 + "</root> " 
                                   + " <root>" + strMessage3 + "</root> " + "</Message1>" + strEnd;

            //Writing strOutContent to output
        } catch (IOException ioException) {
            //If some exception is occurred it is written to mapping trace.
            //stopping the mapping by throwing exception.
            throw new StreamTransformationException(ioException.getMessage());

When this interface (File to File) is run end to end, it will pick up one file and produce 3 output files.

First file content

<?xml version="1.0" encoding="utf-8" ?><root>Payload1</root>

Second file content

<?xml version="1.0" encoding="utf-8" ?><root>Payload2</root>

Third file content
<?xml version="1.0" encoding="utf-8" ?><root>Payload3</root>


You can follow all steps mentioned in this Graphical multi-mapping Link, except graphical mapping (instead implement java mapping).

XSLT multi-mapping Link.

Java multi-mapping (this blog) has the advantages of Java mappings i.e., archiving complex mapping logics.

Use cases

  1. Java Mapping for multi-mapping to split the flat file to different flat files. i.e. let say, if input file is of 15 MB, then it can be split into 3 separate 5 MB files.
  2. XML file can be split. Let say a proxy can handle 999 records at a time. If payload is having 1200 records, then split the message into 2 XML messages. First with 999 records and second with 201 records.
  3. Files rename can be done using variable substitution. i.e. multiple files can be created with dynamic file name, using variable substitution. Note: DynamicConfiguration, cannot be used.


  1. Construct well-formed XML. There are 5 predefined entity references in XML, Add below replace logic, after reading plain text from input.

    strInContent = strInContent.replaceAll("&", "&amp;").replaceAll("<", "&lt;");


  2. HI Raghu,

    First of all i want to ask you one question  how come you are so good in JAVA mapping/SAP PI ? (smile)

    Okie now  my question .

    i am just trying to write my first java mapping in eclipse , in that case i wan to read a file from desktop and write the output after java mapping into another file.

    For that in my class i have written Fileinputstream in=new FileinputStream("input.txt") and Fileoutputstream in=new FileoutputStream("output.txt") in main method.

     how do i pass that file content data to transform method which takes paramater as(TransformationInput transformationInput, TransformationOutput transformationOutput) and once i apply all my logic to the content how to transfer back it to Fileoutputstream?

    It would be very helpful if you show me using the same above example .considering input Payload is in some file and writin my java mapping output into another file.