cancel
Showing results for 
Search instead for 
Did you mean: 

Message mapping/UDF help..

Former Member
0 Kudos

Hi experts,

Can someone let me know whether there is a chance to fulfill the below requirement:

Input file:

In the Input CSV file, there is a fixed length field with length 9 char and has leading zeroes (ex: 000000650)

Output file:

In the O/p XML file, the corresponding value should be displayed as "6.50" (Have to remove the leading zeroes, right justified and the last two digits should be allocated for decimals)

Can anyone let me know if we can handle in Message mapping or should we write a UDF? If so can you please provide the code..

Any help would be highly appreciated !!

Thnx

- Ravi

Accepted Solutions (0)

Answers (7)

Answers (7)

Former Member
0 Kudos

The code in UDF.. a is input parameter..

String str1 = a;

String str2 = null;

String str3 = null;

str1 = str1.replaceFirst("0*","");   // replacing leading zeros with nothing

str2  = str1.substring(str1.length()-2);   // taking out last 2 for decimal places
str3 = str1.substring(0,(str1.length()-2)); // taking rest of the string

return str3 + "." + str2;

Former Member
0 Kudos

Hi,

Check with this UDF

public String change(String a,Container container)
{
  //write your code here
if(a.length() > 0)
{
String b = a.replaceAll("^0*","");
float c = Float.parseFloat(b);
float d = c/100;
String e = Float.toString(d);
return e;
}
else
{
return a;
}
}

src->udf->target

santhosh_kumarv
Active Contributor
0 Kudos

No need of UDF..

Use this mapping format http://www.flickr.com/photos/28929439@N06/2805931373/

Thanks

SaNv...

Former Member
0 Kudos

Hi Ravi,

UDF:

Create a function zerosuppress and take the cache as value and take one argument input. Then put the code below:

//Put this code

String output = input.replaceFirst("^0+","");

return output;

With this function your leading zeros will remove.

Then map like this:

source field --> zerosuppress (udf) --> divide by 100 --> target field.

This should solve your issue.

Regards,

---Satish

Former Member
0 Kudos

sorry wrong input

Former Member
0 Kudos

This can be easy done using graphical mapping no need to use UDF .Use Trim Function to trim the leading zero's then split the number then concat with a . using a constant.

Hope this helps.

Thanks,

Karthik

Former Member
0 Kudos

Hi,

Delete the left side 0's.

while(input.startsWith("0"))

{

String y=input.replaceFirst("0","");

}

return y;

You can divide that number by 100.

or

Import this package : java.text.NumberFormat;

NumberFormat testNumberFormat = NumberFormat.getNumberInstance();

testNumberFormat.setMinimumFractionDigits( 2 );

// Here you can set the numbers, suppose you want the output like 123.589 then set here 3.

testNumberFormat.setMaximumFractionDigits( 2 );

String val1=testNumberFormat.format(input_field_name);

return val1;

Former Member
0 Kudos

try FormatNum

Former Member
0 Kudos

Hi,

I tried that function tab as well but noLuck.. Can you please provide a UDF code

Input String : 000000552

Output : 5.52

Thanks

- Ravi