cancel
Showing results for 
Search instead for 
Did you mean: 

Remove leading zeroes if it is number

Former Member
0 Kudos

Hi,

In the message mapping, idoc to structure,

idoc field of type CHAR, length 10.

possible values in this field are:

1003

PD01

both alphanumeric. Value will be always 4 characters max.

if it is numeric, ex:1003, it is showing with leading zeroes as,

0000001003. But i have to send only 1003, without leading zeroes.

if it is alphanumeric, no issue, it is always left justified & shows only PD01.

i tried to use arithmetic function, ROUND, this is ok for numeric values, but, data will be both. Even i can not use substring, bcoz, numeric value is right justified & alphanumeric is left justified.

If it has to solve by any UDF, plz share the code & the steps to fulfill the same with screen shot if possible.

tnx n rgds,

balu

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

try with the below UDF

use cache parameter as value

//write your code here
String output = a.replaceAll("^0+",""); 
return output;

here a(idoc field) is the input to the udf.

idoc field -


>udf--->tgt field

Answers (4)

Answers (4)

Former Member
0 Kudos

closed

Former Member
0 Kudos

hi,

[;

chk the above thread.

Regards.

Siddhesh

dharamveer_gaur2
Active Contributor
0 Kudos

Hi

UDF: First check String length>4 then

For removing leading zeros

&FieldName(Z)&

or u can use also method suggested by malini after checking string length.

Former Member
0 Kudos

Use a simple UDF. The UDF takes in 1 parameter and returns 1 parameter.

int intVal = Integer.parseInt(a);

return(intVal.toString());

Oops. This will work if the input is a number. But if string value is given it will error out.

Modify the above piece a bit.

String strResult ="";

try{

int intVal = Integer.parseInt(a);

strResult = intVal.toString();

} catch (Exception e)

{

strResult = a;

}

return (strResult);

Edited by: Jaishankar on Sep 27, 2008 2:59 PM