cancel
Showing results for 
Search instead for 
Did you mean: 

Padded zeros which is removed need to be replaced by spaces

Former Member
0 Kudos
115

Hi Friends,

My requirement in XI is : Padded zeros which is removed need to be replaced by spaces.

for removing padded zeros I used the UDF:

int i = Integer.parseInt(a);

return (Integer.toString(i));

It is working fine.

Please help as how to go abt in coding : whatever zeros get taken off , need to be replaced with spaces.

Thanks in Advance,

Meghna.

Accepted Solutions (0)

Answers (3)

Answers (3)

rodrigoalejandro_pertierr
Active Contributor
0 Kudos

hi

is the problem solved??

Former Member
0 Kudos

Hi,

Please take into account that when you replace the 0 with space you won't see it in sxmb_moni because as default internet explorer is removing leading spaces. In order to check it please download message and open in notepad.

BR,

WG

henrique_pinto
Active Contributor
0 Kudos

>String prefix = "";

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

> a = a.substring(1);

> prefix = prefix.concat(" ");

>}

>return prefix.concat(a);

Regards,

Henrique.

Former Member
0 Kudos

Hi Henrique,

Thankyou for responding. Can you please send me the full Java Code that need to be defined in UDF, which includes

1.Removing zeros and also

2.Repalcing zeros by spaces .

Regards,

Meghna.

justin_santhanam
Active Contributor
0 Kudos

Meghna,

In single UDF , you need to remove zeros and Pad spaces for it, isn't it. You can use Henrique's code that will do the logic.

raj.

rodrigoalejandro_pertierr
Active Contributor
0 Kudos

also if you know the lengh of field you can use

for exmaple 10 is the lenght of field

parameter of function (s_str)

String aux = "";

int value = Integrer.parseInt("s_str");

s_str = String.valueOf(value)

for(int i = 0; i<= (10 - s_str.lenght();i++){

aux.concat(" ");

}

retunr aux.concat(s_str);

Former Member
0 Kudos

Hi Raj,

According to the logic given by Henrique, its working. But the point to the noted is that :

The number of spaces need to be equal to the number of zeros removed, where it not happening in this case.for the below Ex when applied it returned ' 12345' instead of ' 12345'.

For ex. source field is '000012345' then the target field need to be ' 12345'.

the Type declared in the data type for the receiver field is integer with length 15.

Is it possible to move the field value to the right justified, so the the padded zeros code when applied will automatically load spaces.Becoz the code written for removing zeros contains String due to which it is left justified i think.

The code written for removing zeros is :

int i = Integer.parseInt(a);

return (Integer.toString(i));

please suggest in this regard.

Regards,

Meghna.

Edited by: meghna swaraj on Feb 27, 2008 6:05 PM

rodrigoalejandro_pertierr
Active Contributor
0 Kudos

try this

parameter of function (s_str)

int L1 = 0;

int L2 = 0;

String s_aux = "";

String s_blanks = "";

int value = Integrer.parseInt("s_str");

String s_aux = String.valueOf(value)

L1 = s_str.lenght();

L2= s_aux.lenght();

L1=L1-L2;

for(int i = 0; i <= L1;i++){

s_blaks.concat(" ");

}

s_blanks.concat(s_aux);

return s_blaks;

Former Member
0 Kudos

Hi Rodrigo Pertierra,

Please mention the code along with the declaration parts.

This is the syntax error i am getting when copied & placed the code:

Source code has syntax error: /usr/sap/XID/DVEBMGS01/j2ee/cluster/server0/./temp/classpath_resolver/Mapc8758fb0e55911dcb23800145e48d1c2/source/com/sap/xi/tf/_MM_PO1_TMS_.java:762: ';' expected parameter of function (s_str) ^ /usr/sap/XID/DVEBMGS01/j2ee/cluster/server0/./temp/classpath_resolver/Mapc8758fb0e55911dcb23800145e48d1c2/source/com/sap/xi/tf/_MM_PO1_TMS_.java:771: ';' expected L1 = s_str.lenght(); ^ 2 errors

Regards,

Meghna.

rodrigoalejandro_pertierr
Active Contributor
0 Kudos

Hi,

//write your code here

int L1 = 0;

int L2 = 0;

String s_aux = "";

String s_blanks = "";

//convert inbound value to integer to delete zeros

int value = Integer.parseInt(s_str);

//convert value to string again

s_aux = String.valueOf(value);

//get length of inbound value and string without zeros

//for determinate hay many blanks i have to add

L1 = s_str.length();

L2= s_aux.length();

L1=L1-L2;

//create an string with blanks

for(int i = 1; i <= L1;i++){

s_blanks = s_blanks.concat(" ");

}

//concat de blanks to string without zeros

//s_blanks.concat(s_aux);

return s_blanks+=s_aux ;

Edited by: Rodrigo Pertierra on Feb 27, 2008 2:59 PM

Edited by: Rodrigo Pertierra on Feb 27, 2008 3:06 PM

henrique_pinto
Active Contributor
0 Kudos

I think your explanation was kind of confusing.

Could you describe what's the actual problem with the udf?

Theoretically, it would be suficient for your needs.

Regards,

Henrique.

Former Member
0 Kudos

Thanks alot Rodrigo Pertierra,

Its working according to my requirement.

rodrigoalejandro_pertierr
Active Contributor
0 Kudos

hi,

if you issue was solved, mark the thread as answed and assing points please

rodrigoalejandro_pertierr
Active Contributor
0 Kudos

hi, can you assing points and close the thread,

thanks you very much

Regards

Rodrigo

former_member439001
Discoverer
0 Kudos

worked for me thanks ... Nice