on 07-04-2013 8:36 PM
Hi Experts ,
I am new to java and i am trying to write an UDF Which will help me in order to achive the below logic
I am trying to get the append logic
If my Source xml code has below values :
<Header_Record>
<Field_Length>10</Field_Length>
<Header_Field>A123</Header_Field>
</Header_Record>
<Data_Record>
<Data_Field>B123</Data_Field>
</Data_Record>
<Data_Record>
<Data_Field>C123</Data_Field>
<Trailer_Record>
<Field>efg</Field>
</Trailer_Record>
then my Target xml message should look like this
<File_Record>A123B123C123efg</File_Record>
I am trying to send the file to Target System in a single record by appending all the records from source message .
kindly suggest me some UDF Codes which i can try out to achieve the logic in ESR .
Regards,
Aziz khan
Hello,
Check this:
Input: var1, var2, var3
Execution type: all values of a context
String out ="";
String second="";
for(int i=0;i<var2.length;i++)
{
second = second + var2[i];
}
out = var1[0] + second + var3[0];
result.addValue(out);
Mapping:
Header_Field-----\
Data_Filed---------UDF----File_Record
Filed---------------- /
Note: Change the context of sources fields and set it to message type name
Thanks
Amit Srivastava
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks all ...My Problem solved .
Regards,
Aziz khan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Aziz,
You can use this UDF which will work out for any number of header/data/trailer records.
Source Structure:
=========================
<Header_Record>
<Field_Length>1</Field_Length>
<Header_Field>H001</Header_Field>
</Header_Record>
<Data_Record>
<Data_Field>D001</Data_Field>
</Data_Record>
<Data_Record>
<Data_Field>D002</Data_Field>
</Data_Record>
<Trailer_Record>
<Trailer_Field>T001</Trailer_Field>
</Trailer_Record>
Target Structure:
=================================
<File_Record>H001D001D002T001</File_Record>
Select the UDS execution type as "All values of context"
UDF Code:
==========================
String maindata = "";
String mainheader = "";
String maintrailer = "";
for( int i = 0; i <var2.length; i++)
maindata = maindata.concat(var2[i]);
for( int i = 0; i <var1.length; i++)
mainheader = mainheader.concat(var1[i]);
for( int i = 0; i <var3.length; i++)
maintrailer = maintrailer.concat(var3[i]);
String out;
out = mainheader.concat(maindata.concat(maintrailer));
result.addValue(out);
===============================================
Normally for header and trailer data, there wont be any repetition of nodes ( 1 header node and 1 trailer nore and multiple data nodes). In that case, you can skip the other two loops in the UDF code.
regards,
Sourav
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
there'a standard function - concat - which you can use to achive that
Regards,
Michal Krawczyk
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
78 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.