cancel
Showing results for 
Search instead for 
Did you mean: 

UDF for creating target field based on length

Former Member
0 Kudos

Hi Experts,

Here is my mapping requirement.

If source value is blank then do not specify the target segment (let's say NAME is target segment name).Form as many target field (lets say name is FIELD) instances (80 chars each) as necessary to accommodate the full length of source value . If special characters * and ~ are found, replace each with a space.

I have 3 conditions here.

---> If source is blank do not specifiy target segment

--->From source i may get value more than 255 characters, target field maximum length is 80, so i need to create more target instances to accomodate full length of source field

---> if special characters * and ~ I need to replace with space.

Can you help to craete UDF which will satify all the above 3 conditions. Thanks for your help.

Source xml:

   <row>

<source>123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789</source>

   </row>

Expected target xml:

<Result>

<TARGET>

<FIELD>12345678912345678912345678912345678912345678912345678912345678912345678912345678</FIELD>

<FIELD>91234567891234567891234567891234567891234567891234567891234567891234567891234567</FIELD>

<FILED>91234567891234567891234567891234567891234567891234567891234567891234567891234567</FIELD>

<FIELD>89123456789123456789123456789123456789</FIELD>

</TARGET>

</Result>

Accepted Solutions (1)

Accepted Solutions (1)

former_member184720
Active Contributor
0 Kudos

Change the target field occurrence to 0..unbounded.

I did this for

source length 9

target length 3

You just need to adjust the lengths..

Answers (1)

Answers (1)

Former Member
0 Kudos

Hello,

Check this UDF:

Input will be var1

Execution type - All values of a context.

if(!var1[0].equals(""))
{
int len = var1[0].length();
int divide = len/80;
String out = "";
int temp = 0;
if(len%80 == 0)
{
for(int i=0;i<divide;i++)
{
temp = 80*i;
out = var1[0].substring (0+temp,80+temp);
result.addValue(out);
}
}
else
{
for(int j=0;j<divide;j++)
{
temp = 80*j;
out = var1[0].substring (0+temp,80+temp);
result.addValue(out);
}
result.addValue (var1[0].substring (divide*80, len));
}
}

else
result.addSuppress();

For removing special characters u can refer the mapping suggested above...But in case ur input contains different kind of special characaters (which u don't know at design time) then u have to adjust ur mapping...

Thanks

Amit Srivastava