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

Frequent question on SDN;

1. How can I map my incoming flat file into a single field of an XML?

2. How can I get the complete payload of a message into a single node/field of an XML?

So this is how it can be done.

 If using PI 7.1 and above, you can use this simple option as mentioned in the below blog;

Else if you are on a version below 7.1; 

Option : JAVA Mapping

 A very simple java code can help you achieve the results. Note that this is not a UDF but a java mapping.


import java.util.Map;

public class PayloadToXMLField implements StreamTransformation {
    String strXML = new String();

	//Declare the XML tag for your XML message
	String StartXMLTag = "<Payload>";
	String EndXMLTag = "</Payload>";

    AbstractTrace trace;
    private Map param = null;

    public void setParameter(Map param) {
        this.param = param;


    public void execute(InputStream in, OutputStream out) {

        trace =
            (AbstractTrace) param.get(
        trace.addInfo("Process Started");

        try {
            StringBuffer strbuffer = new StringBuffer();
            byte[] b = new byte[4096];
            for (int n;(n = != -1;) {
                strbuffer.append(new String(b, 0, n));
            strXML = strbuffer.toString();
        } catch (Exception e) {
            System.out.println("Exception Occurred");

        outputPayload =
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
			+ StartXMLTag
			+ strXML
			+ EndXMLTag;

        try {
			trace.addInfo("Process Completed");;
        } catch (Exception e) {
            trace.addInfo("Process Terminated: Error in writing out payload");;


The code above is extremely simple. All it does is the follows;

1. Converts the inputstream that will contain the source payload (it can be a flat file or XML etc) to string

2. An output string is created using string concat. Assign tags and place the output string which has your complete source between it.

3. Write out the result to an outputstream.


1. In FILE adapter, do not use any FCC parameters. Give the Message protocol as FILE. This is in case you want the whole content of the file to come into XI

2. In java mapping, you will have to use the jar aii_map_api.jar

To locate the jar, Go to your XI server folders and use this path, j2ee\cluster\server0\apps\\ Inside folder you'll find the jar file. Import the jar for your mapping.

1 Comment

  1. Guest

    hi sabharish,

    i got a linkage when i was trying to implement the java mapping mentioned in this wiki.

    could you please suggest any modification. i was using java 1.6 in my machine earlier and then i tried with java 1.5 installed in other machine also but the error didnt resolved.