cancel
Showing results for 
Search instead for 
Did you mean: 

Leading Zeros Supression

Former Member
0 Kudos
416

How Can I supress Leding zeroes into target Structure?. Iam getting 10 digits filled zeros left justified and my target systems doesn't need zeros. Is there Standard function in Mapping I can use?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Ram,

Create a user defined funciton <i><b>zerosuppress</b></i> and take the <i><b>cache</b></i> as value and take one argument <i><b>input</b></i>. Then put the code below:

//write your code here

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

return output;

It will remove all your leading zeros. Let me know whether your issue is resolved or not?

---Satish

Former Member
0 Kudos

Satish - Your code is not working . It gives following errors:

E:/usr/sap/XID/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map1af8bf955eb611dba72f0014220cd5e0/source/com/sap/xi/tf/_testmapping_.java:83: cannot resolve symbol symbol : variable input location: class com.sap.xi.tf._testmapping_ String output = input.replaceFirst("^0+",""); ^ 1 error

Answers (3)

Answers (3)

henrique_pinto
Active Contributor
0 Kudos

Just use standard FormatNum function.

- If you want to use a fixed length of n digits, use 0000..00 (n 0's) as input parameter of the function;

- If you wantg to remove left zeros of a field, use ####...# (n #'s) where n is the maximum length of the field.

Regards,

Henrique.

Former Member
0 Kudos

Thanks Henrique - This is again working partially.When I pass all 0s then it returns me a single 0 which I don't want to blank it out in case of all zeros. Any idea ?

moorthy
Active Contributor
0 Kudos

Hi,

With th ehelp of Substring standard function you can achieve that, if you know the exact number or length.

Elese it is prefer to write a Java User Defined function to achieve the same.

Just check with <i>FormatNum</i> inbuilt functions.

This thread discusses about padding zeros, instead of this, you need to substring it..

Regards,

Moorthy

Former Member
0 Kudos

Hi,

Found one interesting stuff. Try this in a UDF with one arguement "a"

int i = Integer.parseInt(a);

return (Integer.toString(i));

It works, may be JAVA is doing it internally.

Regards,

Jai Shankar.

Former Member
0 Kudos

Jai - In your code, when you all zeros then it returns a single zero "0". So its partially not working. Any suggestion ?

Cheers,

Amrish.

henrique_pinto
Active Contributor
0 Kudos

Amrish,

but "0" is a correct representantion, without left zeros, of "00000000".

If you want to remove all left zeros without distinction, whether it will represent a number or an empty string, just use something like:

...

while (a.startsWith("0")) {

a = a.substring(1);

}

...

Regards,

Henrique.

Former Member
0 Kudos

Thanks Henrique,thaz working

Cheers,

Amrish.

Former Member
0 Kudos

Amrish,

Have your issue is resolved? If not let me know?

---Satish

Former Member
0 Kudos

Thanks Satish for follow up. My problem is solved now.

Cheers,

Amrish.

Former Member
0 Kudos

Hi,

There is a user defined function in Mikall guide that does this.

Former Member
0 Kudos

where is this guide?.

user defined function in Mikall guide that does this