Payload in String need Java mapping to IDOC structure

Hi
I have a payload in a field and that payload needs to  be mapped to IDOC sturcture. As per my understanding I will have to write java mapping for the same.
I don't have any background of java, can anyone help me do this stuff or give me some inputs for the same.
Regards
Ria

Dear Ria,
Does the Source field consists of payload, then there must be original payload for which you have created Source Structure in XI right.
I think your source structure look like this if I'm not wrong:
<Data Type>
    < Field>
      <Field>
       <Field-Payload>
       </Field-Payload>
       </Field>
       </Field>
</DataType>
If this is so, you can split the values in the field by FCC. If your field consists of simple payload you can use String functions to extract the value and map it to IDOC field.
Best Regards
Praveen K

Similar Messages

  • Can i use graphical mapping to do such conversion or do i need java mapping

    Hi Folks,
    Need all your help and experience in solving this .
    Can you let me know is it possible do to such kind of conversion in XI using file adapter or do I need to do java mapping
    Say from rom database I get data in this format
    Seq  Field Name  Field Value
    1    Cust No          Cust 1
    1        S             SS1
    1     Score1            10
    1     Score 2           12
    2     Cust No          Cust 2
    2        S             SS2
    2    Score1            5
    2    Score 2           10
    Based on this my o/p has to be
    Cust 1 SS1 10 12
    Cust 2 SS2 5 10
    ( ie values in the last column )
    The number of rows returned from database can vary . like here for 1 seq it gives 4 in the example bt it can be any number
    Like
    Seq  Field Name  Field Value
    1    Cust No          Cust 1
    1        S             SS1
    1     Score1            10
    1     Score 2           12
    1     Score3            15
    2     Cust No          Cust 2
    2        S             SS2
    2    Score1            5
    2    Score 2           10
    2     Score3            25
    Based on this my o/p has to be
    Cust 1 SS1 10 12 15
    Cust 2 SS2 5 10  25
    is there any way that we can use graphical mapping plus file content conversion to do this or is java based mapping the only solution
    Thanks
    amit

    Hi Amit,
    You can do this using Graphical mapping and File Content Conversion.You concatenate the necessary fields in a Context and assign it to the the field Data(or field name of your wish )) in the target which will of the structure
    <Records>
    <Record>
    <Data>concatenated value</Data>
    </Record>
    </Records>
    and in File Content Conversion
    make Records,Record 0:1 and Data as 0:unbounded
    and give Recordset Structure as Record
    then Record.fieldSeparator as 'nl'
    This will give you desired output
    Regards,
    Sundar

  • Java Mapping using DOM

    Hi All,
    I need Java mapping help. I will get incomming payload as following
    <orders>
    <matnr>123</matnr>
    <qty>10</qty>
    </orders>
    i need to change the above payload as follows
    <ns0:orders>
    <ns0:matnr>123</ns0:matnr>
    <ns0:qty>10</ns0:qty>
    </ns0:orders>
    Please help me how to achieve this using Java mapping.
    Regards
    Vijay

    Hi,
    Dom will be quite expensive for this type of requirement since you will have to go to each element and then append the namespace.
    I suggest you use SAX parser which is more  efficient for such requirement.
    The code is given below you can modify it according to your requirement.
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import javax.xml.parsers.FactoryConfigurationError;
    import javax.xml.parsers.ParserConfigurationException;
    import javax.xml.parsers.SAXParser;
    import javax.xml.parsers.SAXParserFactory;
    import org.xml.sax.Attributes;
    import org.xml.sax.SAXException;
    import org.xml.sax.helpers.DefaultHandler;
    public class SAXDemo extends DefaultHandler{
         public StringBuffer sb = new StringBuffer();
         public String PREFIX = "ns0:";
         int count = 1;
         public static void main(String[] args)
              SAXDemo demo= new SAXDemo();
              demo.saxdemo();
              System.out.println();
         public void saxdemo()
              InputStream in;
              try
                   in = new FileInputStream(new File("Input.xml"));
                   SAXParserFactory factory = SAXParserFactory.newInstance();
                   factory.setNamespaceAware(true);
                   factory.setValidating(false);
                   SAXParser saxParser = factory.newSAXParser();
                   * Parse the content of the given {@link java.io.InputStream}
                   * instance as XML using the specified
                   * {@link org.xml.sax.helpers.DefaultHandler}.
                   * @param inputstream InputStream containing the content to be parsed.
                   * @param cobject The SAX DefaultHandler to use.
                   * @exception IOException If any IO errors occur.
                   * @exception IllegalArgumentException If the given InputStream is null.
                   * @exception SAXException If the underlying parser throws a
                   * SAXException while parsing.               
                   saxParser.parse(in, this);
                   System.out.println(sb.toString());
              catch (FactoryConfigurationError e)
                   e.printStackTrace();
              catch (ParserConfigurationException e)
                   e.printStackTrace();
              catch (SAXException e)
                   e.printStackTrace();
              catch (IOException e)
                   e.printStackTrace();
         public void startDocument()throws SAXException
         public void endDocument()throws SAXException
         public void startElement(String namespaceURI, String name, String qName, Attributes attrs)
         throws SAXException
              if(count == 1)
                   sb.append("<"+PREFIX+qName+" "+PREFIX+"xmlns="+namespaceURI+">");
              else
                   sb.append("<"+name+">");
              count ++;
         public void endElement(String uri, String name, String qName) throws SAXException
              sb.append("</"+qName+">");
         public void characters(char buf[], int offset, int len)
         throws SAXException
              String s = new String(buf, offset, len);
              buf  = null;
              sb.append(s.trim());
                   s = null;
    Regards
    Fariha

  • Java user-defined function for mapping a complex structure

    All,
    Hope one of you can help me with this. I have a structure with over 15 fields and would like to concatenate all the fields into one target field and while I do this, I need to ensure that each field is padded with blanks as defined the data type. Can one of tell me if this is possible with a java user-defined function and if so, what type of logic is needed.
    Input_MT
    Field_1  string len=10 "need"
    Field_2  string len=6 "java"
    Field_3  string len=7 "help"
    Field_4  string len=8  "asap"
    etc,
    Output_MT 
    DataOut string  "need      java  help   asap    "
    (for some reason the exact spaces in between the words disappear in my Preview message)
    I have several fields in the input mt and therefore I find graphical mapping using concatenate and my own user defined function padWithSpace too messy.
    Thank you for you help.

    Hi,
    If your final req is to write all these fields next each other in a file, you can configure this in receiver file adapter by specifying the fixed length for each field.
    If you want the padded string as your MM o/p, you can create a simple user defined funtion with 15 fields as input and 15 constants for their lengths, and find out the length of the each string and pad it with required no of spaces.
    int max_len = 10;
    int actual_len;
    actual_len = a.lengh();
    for(int i=0; i < (max_len-actual_len; i++)
    a = a.append(" ");
    return a;
    praveen

  • Java Mapping - add DOCTYPE

    Hello all -
    I am getting the output in this format:
    <xml version="1.0" encoding="UTF-8"?>
    <Root>
    <SubElement>Test</SubElement>
    </Root>
    How can i achieve the output in this format:
    <xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE XYZ SYSTEM "http://xml.org/xyz.dtd">
    <Root>
    <SubElement>Test</SubElement>
    </Root>
    Please let me know how we can achieve this using Java Mapping and not XSLT.
    Thanks,
    Tirumal

    Prateek -
    Thanks for the response.
    Do we have a step by step approach to how we have to use JAVA mapping?
    My scenario is:
    1. I am able to generate a cXML file from an IDOC ORDERS message type.
    2. I am able to get the <!DOCTYPE ..> line added in the cXML file using the XSLT mapping but there appears to be two extra characters added at the end of the line with '[]'. Read related blogs, bloggers suggsted to use Java mapping as there appears to be a bug in SAP XSLT processor.
    3. Since i am new to JAVA mapping, are there any blogs out there which gives us step by step approach to using JAva mapping for IDOC(s)/ORDERS message typ.
    Thanks,
    Tirumal

  • Fields to be mapped for Idoc/Xi interface

    For customer collaboration we need to map the Idoc/Xi interface for following things
    In FS what field should be mentioned for following
         u2022     Integration SNC with R/3:
    u2022     ORDERS (PI) (Order Creation)
    u2022     ORDERSP (PI) (Order Confirmation)
    u2022     DESADV (PI) (ASN)
    u2022     Integration with the customer
    o     PROACT = new integration with SNC (PI)
    o     Product Forecast Notification
    o     ( Order ID Notification ) - To be evaluated for PO nrs.
    o     ORDERSP = AS IS
    o     DESADV = AS IS
    o     Proof of Delivery

    I am closing this Thread
    Thanks

  • Dynamic nuber of fields during java map

    my src structure
    <appointment>
    <empno> 1 </empno>
    <empno>2 </empno>
    </appointment>
    empno is 0..unbounded.
    how do we know how may times this empno element is coming in the source
    I have a setempno method and getempno method inside appointment class.
    private String[] empno = null;
    public void setempno (String o){
                   empno<i> = o;
              public String getempno (int i){
                   return empno<i>;
    but as i initialized empno[] = null; it is taking null and could not retrive how many empno are coming.

    Iam not using message mapping, iam using java mapping .
    my src structure
    <appointment>
    <empno> 1 </empno>
    <empno>2 </empno>
    </appointment>
    empno is 0..unbounded.
    appointment is 0..unbounded
    as I said Iam SAX parser, i have setter and getter methods, to set the values.
    what shud be written to capture all the elements under appointment.

  • File to IDOC Scenario: where to import the idoc structure?

    Dear all,
    I have a short organizational question for you all. I have created a scenario where the MDM server places a file in a FTP directory and XI will take it from there for processing to IDOC towards the SAP system.
    During design time I need to import the IDOC structure as the inbound interface for the SAP system.
    My question in this situation is: do I import the IDOC into the namespace of the MDM (in which I keep the outbound interface and the mappings) server or do I place it in the namespace of the SAP system?
    I ask this because in the latter case the IDOC structure will be the only object in the SAP namespace. If I do not do this, I don't have to create this.
    What is the right thing to do from an organizational point of view?
    Thanks in advance for your input.

    Hi Yomesh and Sudheer,
    thanks for your answers. To conclude this topic I will demonstrate how I have understood this all by giving you a short overview of how I will proceed now. Could you please comment???
    Sender system is a SAP MDM system. For which I will create a SWC called <Company name>_MDM_DEV version 1.0.
    For the receiving SAP Enterprise system I will create an additional SWC called <Company name>_SAP_DEV version 1.0.
    And thus I do not put any objects under SWCs from the original installed product components.
    Then I create a SWC for common objects as IDOCs (to what product does that need to be assigned???)
    Then I will put the interface and message types in the corresponding SWCs and put the mappings in the source SWC as our landscape is not that huge.
    How's that???
    So under which product to create the SWC for common objects is my final question...
    I will provide points to you both.
    Cheers,
    Auke
    Message was edited by:
            A. Schotanus

  • IDOC structure for shipment document

    Dear All,
      I need to know the IDOC structure to use for shipment document which will be updated with the actual shipment start end end times.(for carrier stop confirmation update interface.)
    Please let me knnow.
    Thanks in Advance.
    KCR

    Hi KCR,
    Check the Message Type SHPMNT for IDOC types SHPMNT01,02,03,04,05.
    Thanks & Regards,
    YJR.

  • File to Idoc : Java Mapping

    Hi Experts,
    The scenario is file to idoc. In the file i'll be getting name,value pairs. For ex:
    Structure is
    MT
    ....Root(1..unbounded)
    ............Name
    ............Value
    File contains:
    Vishal....1
    Raj.........2
    RFC......10
    Rahul.....20
    Azhar....15 and so on..
    I need to loop through the file. When Name="RFC", I need to make an RFC call with Value as it's input. RFC returns 4 values which will be used for mapping.
    Then I need to continue looping through the file. On encountering a particular Name, I need to map corresponding Value to target field.
    For this, I should have 2 mappings. One to read the file and the other for mapping. I've never used RFC and Java mapping, Can someone provide me a link or a solution for this?
    Thanks,
    Vishal

    Hi,
    You can do this using a UDF.
    first let the source message contain first line and last line which you want to eliminate.
    change the context of the Value to MT ..
    start a for loop in UDF ignoring first & last line like
    for(int i = 1; i< input.length() - 1; i++)  // here i = 1 & not zero  & input length is -1 so that first & last field eliminates
           //carry on string operation to separate name & value on delimeter space
    String name = input<i>.subString(0,.... to the indexOf space);
    //similar for value also....
    now you have name & value
    check for name == 0052
    if(name == 0052)
      perform rfc lookup
    else

  • Calling IDoc structure from IDOC metadata into Java mapping.

    Hi All,
    I have a requirement where we need to post an IDOC on target side, We are having to go for  a Java Mapping ,so  I need to create a Target XML with IDOC Structure, So i need to understand if we could import the structure from IDOC Meta Data  in to the Java Mapping insted of creating the IDOC Structure, I am using DOM parser for my Java Mapping,
    Really appreciate your response in this regard.
    Best Regards
    Jayaram

    Hi Jayram,
    In your requirement, get the xsd format of the idoc from idoc structure and using String xsdFormat ="xsd retrieved";  in the java mapping, you can create the xml structure using DOM parse APIs and then you can put values into the structure and pass it.
    Thanks,
    RK

  • Java Mapping: payload as mail attachment and dynamic file name .

    Hi,
    I have written this piece of java code.
    The code includes XPATH for fetching dynamic filename and the copysource( in, out ) to copy the content of payload as mail attchment.
    The code seems to work fine, when either of the functionality is implemented.
    but when both are implemented together ie parsing for xpath then again parsing to copy payload, then it doesnt executes the latter path i.e the payload is not fetched in the attachment.
    public class MailPackage implements StreamTransformation {
      public void setParameter(Map map) {
      public void execute(InputStream in, OutputStream out)
              throws StreamTransformationException {
      String mailSubject = "test mail";
      String mailSender = "aaaaaaaa";
      String mailReceiver = "[email protected]";
      String attachmentName = null;
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = null;
      factory.setNamespaceAware(false);
    factory.setValidating(false);
         try {
              builder = factory.newDocumentBuilder();
         Document doc = null;
          doc = builder.parse(in);
              String XPATH ="/*/Invoice/InvoiceHeader/InvoiceNumber/text()";
              Node fieldValueNode = org.apache.xpath.XPathAPI.selectSingleNode(doc,XPATH);
              System.out.print(fieldValueNode);
              attachmentName = fieldValueNode.getNodeValue() +".xml";
      String boundary = "--";
      String mailContent = "This is a sample file";
      String CRLF = "\r\n";
        //     create XML structure of mail package
        String output ="<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
               + "<ns:Mail xmlns:ns=\"http://sap.com/xi/XI/Mail/30\">"
               + "<Subject>" + mailSubject     + "</Subject>"
               + "<From>" + mailSender     + "</From>"
               + "<To>" + mailReceiver     + "</To>"
               + "<Content_Type>multipart/mixed; boundary=\"" + boundary + "\"</Content_Type>"
               + "<Content>";
        out.write(output.getBytes());
        // create the declaration of the MIME parts
        //First part
        output = "--" + boundary + CRLF
               + "Content-Type: text/plain; charset=UTF-8" + CRLF
               + "Content-Disposition: inline" + CRLF + CRLF
               + mailContent + CRLF
        //Second part
        + "--" + boundary + CRLF
        + "Content-Type: application/xml; name=" + attachmentName + CRLF
        + "Content-Disposition: attachment; filename=" + attachmentName + CRLF + CRLF;
        out.write(output.getBytes());
        //Source is taken as attachment
        copySource(in, out);
        out.write("</Content></ns:Mail>".getBytes());
      } catch (Exception ie) {
        throw new StreamTransformationException(ie.getMessage());
    protected static void copySource(InputStream in, OutputStream out)throws IOException {
        byte[] bbuf = new byte[in.available()];
        int bblen = in.read(bbuf);
       if (!(bblen < 0)) {
          String sbuf = new String(bbuf);
           //replace all control characters with escape sequences
         sbuf = sbuf.replaceAll("&", "&amp;");
         sbuf = sbuf.replaceAll("\"", "&quot;");
         sbuf = sbuf.replaceAll("'", "&apos;");
        sbuf = sbuf.replaceAll("<", "&lt;");
        sbuf = sbuf.replaceAll(">", "&gt;");
        out.write(sbuf.getBytes());
    Povide your suggestions.

    Hi,
    This is the sample o/p that I get by opening the mail attachment using notepad.
    <?xml version="1.0" encoding="UTF-8"?>
    <InvoiceTransmission><InvoiceTransmissionHeader><InvoiceCreationDate>2008-12-03T00:00:00</InvoiceCreationDate><Version>2.0.2</Version></InvoiceTransmissionHeader><Invoice><InvoiceHeader><CustomerEntityID>LH</CustomerEntityID><IssuingEntityID>009140559</IssuingEntityID><InvoiceNumber>913353669</InvoiceNumber><InvoiceIssueDate>2008-12-03</InvoiceIssueDate><InvoiceType InvoiceTransactionType="OR">INV</InvoiceType><InvoiceDeliveryLocation>aaa</InvoiceDeliveryLocation><TaxInvoiceNumber>Not Applicable</TaxInvoiceNumber><InvoiceCurrencyCode>USD</InvoiceCurrencyCode><InvoiceTotalAmount>517174.63</InvoiceTotalAmount><InvoiceIDDetails InvoiceIDType="BT"><InvoiceIDVATRegistrationNumber>0000000000</InvoiceIDVATRegistrationNumber><InvoiceIDName1>aaaaaaaaaaaaaaa</InvoiceIDName1><InvoiceIDName2>bbbbbbHKG</InvoiceIDName2><InvoiceIDCity>ccccccccc ccccc</InvoiceIDCity><InvoiceIDCountryCode>HK</InvoiceIDCountryCode></InvoiceIDDetails><InvoiceIDDetails InvoiceIDType="II"><InvoiceIDVATRegistrationNumber>0000000000</InvoiceIDVATRegistrationNumber><InvoiceIDName1>eeeeeeee</InvoiceIDName1><InvoiceIDName2>PAY BY WIRE TRANSFER</InvoiceIDName2><InvoiceIDCity>fffffffffffffff, NA</InvoiceIDCity><InvoiceIDCustomField ID="1"><InvoiceIDCustomFieldDescription>Company Registration Number</InvoiceIDCustomFieldDescription><InvoiceIDCustomFieldValue>0000000000</InvoiceIDCustomFieldValue></InvoiceIDCustomField></InvoiceIDDetails></InvoiceHeader><SubInvoiceHeader><InvoiceLine><ItemNumber>001</ItemNumber><ItemQuantity><ItemQuantityType>IN</ItemQuantityType><ItemQuantityFlag>GR</ItemQuantityFlag><ItemQuantityQty>28134.000</ItemQuantityQty><ItemQuantityUOM>USG</ItemQuantityUOM></ItemQuantity><ItemQuantity><ItemQuantityType>DL</ItemQuantityType><ItemQuantityFlag>GR</ItemQuantityFlag><ItemQuantityQty>106498.775</ItemQuantityQty><ItemQuantityUOM>LT</ItemQuantityUOM></ItemQuantity><ItemDeliveryReferenceValue ItemDeliveryReferenceType="DTN">590365</ItemDeliveryReferenceValue><ItemDeliveryReferenceValue ItemDeliveryReferenceType="!
    ARN">DAL
    CH</ItemDeliveryReferenceValue><ItemDeliveryReferenceValue ItemDeliveryReferenceType="FNO">mmmmmmmmm</ItemDeliveryReferenceValue><ItemDeliveryLocation>pppp</ItemDeliveryLocation><ItemReferenceLocalDate
    If you notice the problem is, the undesired "exclamation mark" that gets added in some fields before the actual value.
    In the above case.. look at "ItemDeliveryReferenceType="! ARN">DAL"
    the exclamation mark before value "ARN is unwanted, which leads to improper XML formation.
    Cant figure out why is this coming.
    Regards,
    Faria Mithani

  • XML to string using xslt or java mapping

    Hi Experts,
    I want to put xml into string and i need to change lessthan symbol to "&lt"   and greaterthan symbol to "&gt" , can anyone please help me how to do this??? can you provide code for java mapping or XSLT mapping to achive this.
    SOURCE
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:source_mt xmlns:ns0="urn:ppp:prototype">
       <row>
          <name1>IT</name1>
          <name2>SOLUTIONS</name2>
       </row>
    </ns0:source_mt>
    TARGET
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:target_mt xmlns:ns0="urn:ppp:prototype">
       <row>
          <Body>"&lt"name1"&gt" IT"&lt"/name1"&gt" "&lt"name2"&gt" SOLUTIONS"&lt";/name2"&gt" </Body>
       </row>
    </ns0:target_mt>

    Hi ,
          here is the XSLT code to obtain the desired output
    <xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml"/>
    <xsl:template match="/">
    <ns0:target_mt xmlns:ns0="urn:ppp:prototype">
         <xsl:for-each select="//row">
              <row>
                   <Body>
                        <xsl:for-each select="name1">
                                  <xsl:value-of select="concat('*&quot;&lt;&quot;name1&quot;&gt;&quot;*',normalize-space(.),'*&quot;&lt;&quot;/name1&quot;&gt;&quot;*')"></xsl:value-of>
                        </xsl:for-each>     
                        <xsl:for-each select="name2">
                                  <xsl:value-of select="concat('*&quot;&lt;&quot;name2&quot;&gt;&quot;*',normalize-space(.),'*&quot;&lt;&quot;/name2&quot;&gt;&quot;*')"></xsl:value-of>
                        </xsl:for-each>
                   </Body>
              </row>
         </xsl:for-each>
    </ns0:target_mt>      
    </xsl:template>
    </xsl:stylesheet>
    output produced as viewed in browser is
    http://postimage.org/image/1lqbgw8kk/
    Now to obtain exactly the output you posted earlier here is the code
    <xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml"/>
    <xsl:template match="/">
    <ns0:target_mt xmlns:ns0="urn:ppp:prototype">
         <xsl:for-each select="//row">
              <row>
                   <Body>
                        <xsl:for-each select="name1">
                                  <xsl:value-of select="concat('*&quot;&amp;lt&quot;name1&quot;&amp;gt&quot;*',normalize-space(.),'*&quot;&amp;lt&quot;/name1&quot;&amp;gt&quot;*')"></xsl:value-of>
                        </xsl:for-each>     
                        <xsl:for-each select="name2">
                                  <xsl:value-of select="concat('*&quot;&amp;lt&quot;name2&quot;&amp;gt&quot;*',normalize-space(.),'*&quot;&amp;lt&quot;/name2&quot;&amp;gt&quot;*')"></xsl:value-of>
                        </xsl:for-each>
                   </Body>
              </row>
         </xsl:for-each>
    </ns0:target_mt>      
    </xsl:template>
    </xsl:stylesheet>
    output you can see from link below
    http://postimage.org/image/2c7bzo478
    Hope this helps.
    Hi,
        Could you please kindly let us know if the solution is working properly as per your requirement?
    regards
    Anupam
    Edited by: anupamsap on Jul 26, 2011 6:29 AM
    Edited by: anupamsap on Jul 26, 2011 4:10 PM

  • Java Mapping/UDF/ABAP mapping to capture payload

    Hi,
    could you please provide me Java mapping code samples (or UDF code) to save payloads of a message based on Message ID
    i have a synchronous scenario where i have payloads in sxmb_moni for request and response with different message IDs. So pelase let me know how to save those request and response payloads to a file.
    it would be great if you provide the stpes to implement and java code samples....if it is possible with ABAP mapping also please let me know te steps.
    Best Regards....SARAN

    Try with this code
    import com.sap.mw.jco.IFunctionTemplate;
    import com.sap.mw.jco.IRepository;
    import com.sap.mw.jco.JCO;
    public class PayloadExtractor {
        // The MySAP.com system we gonna be using
        static final String SID = "SID";
        // The repository we will be using
       IRepository repository;
        JCO.Field msgkeyField;
        public PayloadExtractor() {
            try {
                System.out.println("*** Creating the Pool... ***");
                JCO.addClientPool(SID, 10, "001", "user", "pwd", "EN", "host", "00");
                repository = JCO.createRepository("RecoverRepository", SID);
            } catch (JCO.Exception ex) {
                System.out.println("RecoverXI Caught an exception: \n" + ex);
        // Retrieves and prints information about the remote system
        public void getPayload() {
            // A messageID from your XI/PI
            String key = "48CD01EB3D27021BE1008000C0A8477D";
            final String pipelineID = "CENTRAL";
            byte[] msgkey = key.getBytes();
            try {
                IFunctionTemplate ftemplate = repository.getFunctionTemplate("SXMB_READ_MESSAGE_VERSION_RAW");
                if (ftemplate != null) {
                    System.out.println("*** Creating client and function... ***");
                    JCO.Function function = ftemplate.getFunction();
                    JCO.Client client = JCO.getClient(SID);
                    JCO.Structure struct = function.getImportParameterList().getStructure("MESSAGEKEY");
                    struct.setValue(key, "MSGID");
                    struct.setValue(pipelineID, "PID");
                    // SELECTION must be like this!
                    function.getImportParameterList().getField("SELECTION").setValue("2");
                    // This is the msg version number, where 000 is the first (Inbound); the last can be caught from the function output (see below).
                    // Setting this strongly depends on what you want to get: basically before or after the mapping...
                    function.getImportParameterList().getField("VERSION_REQUEST").setValue("000");
                    System.out.println("*** Calling... ***");
                    client.execute(function);
                    JCO.Table tb = function.getExportParameterList().getTable("MESSAGEPAYLOAD");
                    if (tb.getNumRows() > 0) {
                        // There could be multiple payloads (even if usually it's only one)
                        do {
                            String plstr = new String(tb.getField("PAYLOAD").getByteArray());
                            System.out.println(
                                "*** Payload found *** " + tb.getField("NAME").getString() + " *** BEGIN ***");
                            System.out.println(
                                "Message Last Version: "
                                    + function.getExportParameterList().getField("MAXVERSION").getString());
                            System.out.println(plstr);
                            System.out.println(
                                "*** Payload found *** " + tb.getField("NAME").getString() + " ***  END  ***");
                        } while (tb.nextRow());
                    } else {
                        System.out.println("*** No payload found! ***");
                    // Release the client into the pool
                    JCO.releaseClient(client);
                } else {
                    System.out.println("Function SXMB_READ_MESSAGE_VERSION_RAW not found in backend system.");
            } catch (Exception ex) {
                System.out.println("Caught an exception: \n" + ex);
        protected void cleanUp() {
            System.out.println("*** Cleaning... ***");
            JCO.removeClientPool(SID);
        public static void main(String[] argv) {
            PayloadExtractor e = new PayloadExtractor();
            e.getPayload();
            e.cleanUp();
    -Madhu

  • How to Use IDOC in Java Mapping?

    Hello -
    1. How can i use an IDOC to map to an xml file using Java mapping in an IDOC -> XI -> XML file scenario?
    2. How can i test this scenario outside XI, i mean using Eclipse?
    3. How can i create a test data for IDOC for the above scenario in XML format to test it using Java program?
    Thanks,
    Tirumal

    Hi,
    <i>***1. How can i use an IDOC to map to an xml file using Java mapping in an IDOC -> XI -> XML file scenario?</i>
    It will be a direct xml to xml mapping. Is your requirement requires Java Mapping? Otherwise you can easily do without that - check this-
    Is there simply way to map an idoc to an flatfile?
    <i>***2. How can i test this scenario outside XI, i mean using Eclipse?</i>
    You need to have XML input for this. Just try to get the IDoc XML or create xml input based on the Idoc Structure. You can make use of  WE60 to get  IDOC xsd .
    <i>***3. How can i create a test data for IDOC for the above scenario in XML format to test it using Java program?</i>
    Go to Tcode WE19 in the R/3 and generate the outbound Idoc . And then use that xml ( for question no 2). as a test data to test independently.
    Hope this helps..
    Regards,
    Moorthy

Maybe you are looking for