cancel
Showing results for 
Search instead for 
Did you mean: 

Split a string into a table by a function

Former Member
0 Kudos

Hi everybody,

I'd like to split a long string into smaller part fixed lenght in a mapping.

I have an XML as input like

<MT010_input>

<row>

<field>firstdefinitionttttttttttttttttttttttttttttttttt</field>

</row>

<MT010_input>

and I'd like to have at the output an XML like

<MT010_output>

<item>

<part>first</part>

</item>

<item>

<part>defin</part>

</item>

.....

</MT010_output>

Here in the example, I split the string of <field> into <part> with a length of 5 characters

ThIs is probablbly can be done in a user defined function .

Can anybody help me ?

I'm not an expert in java .

Thank you in advance for your help.

Kind regards

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Eric

You can use the following code in the mapping

while((field[0].length()-5)>0)

{

result.addValue(field[0].substring(0,5));

result.addContextChange();

field[0]=field[0].substring(5,field[0].length());

}

result.addValue(field[0]);

Regards

Ram

Former Member
0 Kudos

Ram,

Thank you very much for your help.

that solved my issue.

Kind Regards.

E.Koralewski

Answers (2)

Answers (2)

Former Member
0 Kudos

Refer the below blog for more info on writing UDF fn.

/people/rohit.kalugade/blog/2008/12/08/context-and-queue-in-message-mapping-udf

/people/harrison.holland5/blog/2006/12/08/mapping-context-changes-in-xi

Regards

Ramg

Former Member
0 Kudos

Hi

1. Use the Substring in your function,

2. add the value to the resut (result.addValue)

3. Add Context Change (result.addContextchange)

Regards

Ramg