cancel
Showing results for 
Search instead for 
Did you mean: 

Lpadding zeroes to a string in message mapping- material/customer format

Former Member
0 Kudos

Hi

I have a scenario which I guess - all of you would have faced if you calling a SAP std BAPI/RFC through XI from an external client application to read some information based on SAP material/customer

Normally, to get details of a material by calling a relevant RFC in SAP - for eg : if the material number contains only numbers ( no alpha ), then , when calling the RFC , the material string has to be lpadded with zeroes for the remaining lenght upto 18. This lpadding need not be done in case the material string contains an alpha character.

I tried lpadding the remaining length -say for the material using number format function in XI message mapping- but obviously this fails if the material string contains an alpha character....

Obviously , there has to be a check - whether the material string passed from the client application contains an alpha or not. If there is an alpha character , there is no need to lpad, otherwise there is a lpadding necessary.

1. Can this check for presence of an alpha character be done using the graphical editor and pre-defined functions ? Or do we have to write a advanced function using Java to do this ?

2. Can the whole logic of mapping the material number to the format required by the RFC be done using the graphical editor with the pre-defined functions

Can anybody share the advanced function code or some technicalities in the graphical mapping to achieve the whole mapping or atleast the check for the alpha character ?

Thank you in advance for your time.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Karthik,

Here's the easiest way to do this:

1) Write a java function called isNumeric to check if the value is numeric. There are lots of ways to do this. Here's the simplest:

try {

Integer.parseInt(a);

} catch (NumberFormatException e) {

return false;

}

return true;

2) Use the built-in FormatNum function to pad the zeros. There's no need to write java code to do this. If you want to pad to 10 places, specify 0000000000 as the format.

3) Setup an If-Else statement. If isNumeric then FormatNum else just pass the value unchanged.

Thanks,

Jesse

Former Member
0 Kudos

Hi people,

Thanks to all of you. I was specifically looking for a java function that checks whether string is numeric or not. Thanks to Jesse, I got that solution rightaway.

Thanks for your quick response.

Former Member
0 Kudos

Hi Kirthik,

Good, I'm glad it worked for you.

Here's a little cleaner version that doesn't have 2 return statements in it.

boolean isNumeric;

try {

Integer.parseInt(inputStr);

isNumeric = true;

} catch (NumberFormatException e) {

isNumeric = false;

}

return isNumeric;

Thanks,

Jesse

Answers (2)

Answers (2)

MichalKrawczyk
Active Contributor
0 Kudos

Hi,

have a look at this piece of code:

String vendornum = "asd13342";

String Returnvend = null;

String zero = "0";

int strlength = vendornum.length();

int standardlength = 18;

Returnvend = vendornum ;

for (int i = strlength ; i< standardlength; i++)

{

Returnvend = zero.concat(Returnvend);

}

return Returnvend;

(you can adopt it to your simple use function)

Regards,

michal

Former Member
0 Kudos

Hi,

create a user defined fucntion with one parameter, usually the parameter will be defaulted to "a".

Use the following code

for( int i =0 ; i < 18 - a.length() ; i ++)

a += "0";

return a;

cheers,

Naveen

Message was edited by: Naveen Pandrangi

Former Member
0 Kudos

Hi Karthik,

Check these threads

Regards

Anand