cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple Source Fields to Single Target Field

0 Kudos

Hello PI Experts,

Needed help with message mapping, I have multiple source fields with multiple structures and need to pass it to a single target field. What is the best way to achieve this? Can anybody share any idea or perhaps UDF code? Can this be achieved using 'Return as XML' in graphical message mapping?

Thanks,

John

Accepted Solutions (1)

Accepted Solutions (1)

former_member184720
Active Contributor
0 Kudos

Please check the below doc  for 'Retrun as Xml' use case -

http://scn.sap.com/people/jyothi.anagani/blog/2010/06/17/convert-the-input-xml-to-string-in-pi-71-us...

If your requirement is simillar then you can go for it

0 Kudos

Thank you Hareesh, that was the example I was trying to use but exploring other options.

Answers (4)

Answers (4)

Former Member
0 Kudos

Hello,

>>I have multiple source fields with multiple structures and need to pass it to a single target field.

U want ur source structure to be returned as xml string or xml structure??

“Return as XML” – returns the source node as XML structure (due to the presence of Xml definition tag <?xml version="1.0" encoding="UTF-8"?> ) which eventually create xml nodes beneath ur target element instead of assigning xml string value to it.

In case you want to pass input structure as a xml string to ur target field then u have to remove XML declaration before assigning source node to target element.

Something like:

Source Node (Return as XML)

Constant (<?xml version="1.0" encoding="UTF-8"?>)------Replace String --- Target Field

Constant()

Thanks

Amit Srivastava

rhviana
Active Contributor
0 Kudos

John I recommend UDF or Java Mapping.

Try the code provide fro Virkrant.

Kind regards,

vkaushik82
Active Participant
0 Kudos

Concat all fields and use UDF

Suppose if i have 2 fields Field 1 & Field 2

  • Concat Field 1 & Field 2
  • Pass it UDF using  all value of context.

UDF code you can use as below

for (int i=0;i<var1.length;i++)
{
s=s.concat(var1[i] );
}

result.addValue(s);

I am not sure if i understood your problem correctly.Let us know more details

0 Kudos

Thank you Vikrant & Ricardo, I will try the UDF and see if that works. I'll reply back again.

0 Kudos

Hello Vikrant,

I tried the udf code you gave but getting errors when checking. Here is my source and target structure:

Source Structure:

<?xml version="1.0" encoding="UTF-8"?>

<xsd:schema targetNamespace="urn:mmtest" xmlns="urn:mmtest" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

  <xsd:element name="MT_Source" type="DT_Source"/>

  <xsd:complexType name="DT_Source">

      <xsd:annotation>

        <xsd:appinfo source="http://sap.com/xi/VersionID">8eaac9e8724811e3c9c30000003aec92</xsd:appinfo>

      </xsd:annotation>

      <xsd:sequence>

        <xsd:element name="Lvl1">

            <xsd:complexType>

              <xsd:sequence>

                  <xsd:element name="Field1" type="xsd:string" minOccurs="0"/>

                  <xsd:element name="Field2" type="xsd:string" minOccurs="0"/>

                  <xsd:element name="Field3" type="xsd:string" minOccurs="0"/>

              </xsd:sequence>

            </xsd:complexType>

        </xsd:element>

        <xsd:element name="Lvl2">

            <xsd:complexType>

              <xsd:sequence>

                  <xsd:element name="Field1" type="xsd:string" minOccurs="0"/>

                  <xsd:element name="Field2" type="xsd:string" minOccurs="0"/>

                  <xsd:element name="Field3" type="xsd:string" minOccurs="0"/>

              </xsd:sequence>

            </xsd:complexType>

        </xsd:element>

        <xsd:element name="Lvl3">

            <xsd:complexType>

              <xsd:sequence>

                  <xsd:element name="Field1" type="xsd:string" minOccurs="0"/>

                  <xsd:element name="Field2" type="xsd:string" minOccurs="0"/>

                  <xsd:element name="Field3" type="xsd:string" minOccurs="0"/>

              </xsd:sequence>

            </xsd:complexType>

        </xsd:element>

        <xsd:element name="Lvl4">

            <xsd:complexType>

              <xsd:sequence>

                  <xsd:element name="Field1" type="xsd:string" minOccurs="0"/>

                  <xsd:element name="Field2" type="xsd:string" minOccurs="0"/>

                  <xsd:element name="Field3" type="xsd:string" minOccurs="0"/>

              </xsd:sequence>

            </xsd:complexType>

        </xsd:element>

        <xsd:element name="Lvl5">

            <xsd:complexType>

              <xsd:sequence>

                  <xsd:element name="Field1" type="xsd:string" minOccurs="0"/>

                  <xsd:element name="Field2" type="xsd:string" minOccurs="0"/>

                  <xsd:element name="Field3" type="xsd:string" minOccurs="0"/>

              </xsd:sequence>

            </xsd:complexType>

        </xsd:element>

      </xsd:sequence>

  </xsd:complexType>

</xsd:schema>

<?xml version="1.0" encoding="UTF-8"?>

Target Structure:

<xsd:schema targetNamespace="urn:mmtest" xmlns="urn:mmtest" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

  <xsd:element name="MT_Target" type="DT_Target"/>

  <xsd:complexType name="DT_Target">

      <xsd:annotation>

        <xsd:appinfo source="http://sap.com/xi/VersionID">fd6f61cc724711e398e50000003aec92</xsd:appinfo>

      </xsd:annotation>

      <xsd:sequence>

        <xsd:element name="strg2xml" type="xsd:string" minOccurs="0"/>

      </xsd:sequence>

  </xsd:complexType>

</xsd:schema>

Errors in UDF:

cannot find symbol symbol  : method concat(java.lang.String) location: class java.lang.String[] s=s.concat(var1[i] );

cannot find symbol symbol  : variable result location: class com.sap.xi.tf._MM_Test1_ result.addValue(s);

vkaushik82
Active Participant
0 Kudos

try as below it will work.

I am only showing root LvL1 & Lvl2 , similarly you can do for others.

Keep the field context to MT_Source.

UDF

String s=new String("");

for (int i=0;i<var1.length;i++)
{
s=s.concat(var1[i] );

}

result.addValue(s);

Java mapping is also a good option.

0 Kudos

Vikrant,

Thanks for your help.

I tried doing the way put in your reply but getting the output with values only, does not give like <field1>value</field1>, etc. This is not the output expected. Please see below:

<?xml version="1.0" encoding="UTF-8"?>

<ns0:MT_Target xmlns:ns0="urn:mmtest"><strg2xml>onetwothreefourfivesixseveneightnineteneleventwelvethirteenfourteenfifteen</strg2xml></ns0:MT_Target>

former_member184720
Active Contributor
0 Kudos

Hi John,

Can you provide additional details. May be sample xml and target structure.

You can use concat function and appened all the fields and send it to one target field.