cancel
Showing results for 
Search instead for 
Did you mean: 

Check if a Value is Numeric

Former Member
0 Kudos

Hello All,

I wanted to check if a field value is numeric or not. I tried working around with standard XI mapping functions, but could never get it working. Are there any UDF's to check the value if its numeric or not? I tried writing a UDF, but could not get it working.

I appreciate it if someone can give me some pointers.

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

justin_santhanam
Active Contributor
0 Kudos

Balu,

Do u want to return boolean value say yes or no based on the numeric value?

12345 - Yes

123AB - No

This what do u want?

-raj.

Former Member
0 Kudos

> Balu,

>

> Do u want to return boolean value say yes or no based

> on the numeric value?

>

> 12345 - Yes

> 123AB - No

>

> This what do u want?

>

> -raj.

Raj,

Thats exactly what I want.

Former Member
0 Kudos

Hi Balu,

Use the follwing UDF which will return if it is numeric otherwise return 0

   //write your code here
 int x = 0;
try{	
Integer.parseInt(a);
return a;                }	
catch(NumberFormatException e){                       return "0";           }

Warm Regards,

Vijay

justin_santhanam
Active Contributor
0 Kudos

Balu,

Try this.

int k;

String bool="";

try

{

k=Integer.parseInt(a);

bool="true";

}

catch(Exception e)

{

bool="false";

}

return ""bool"";

-raj.

justin_santhanam
Active Contributor
0 Kudos

Oops!! sorry. I didn't checked vijay's reply. Use either one.

-raj.

Former Member
0 Kudos

This UDF is working with a numeric value. But If there is a Alphanumeric value, it shoud return 0 (zero) right?? Instead its throwing a Runtimre exception .

<b>RuntimeException in Message-Mapping transformation: Runtime exception during processing target field mapping /MBGMCR02/IDOC/E1BP2017_GM_ITEM_CREATE/MOVE_TYPE. The message is: Exception:[java.lang.IllegalArgumentException: Cannot cast 300A to float. ] in class com.sap.aii.mappingtool.flib3.Arithm method div[300A, 300A, com.sap.aii.mappingtool.tf3.rt.Context@1af41af4]</b>> Hi Balu,

>

> Use the follwing UDF which will return if it is

> numeric otherwise return 0

>

>

   //write your code here
>  int x = 0;
> ry{	
> Integer.parseInt(a);
> return a;                }	
> catch(NumberFormatException e){
>                       return "0";           }

Former Member
0 Kudos

Vijaya,

Ignore my earlier post. The UDF that you suggested works. Thanks for your help.

Balu

> This UDF is working with a numeric value. But If

> there is a Alphanumeric value, it shoud return 0

> (zero) right?? Instead its throwing a Runtimre

> exception .

>

> <b>RuntimeException in Message-Mapping

> transformation: Runtime exception during processing

> target field mapping

> /MBGMCR02/IDOC/E1BP2017_GM_ITEM_CREATE/MOVE_TYPE. The

> message is:

> Exception:[java.lang.IllegalArgumentException: Cannot

> cast 300A to float. ] in class

> com.sap.aii.mappingtool.flib3.Arithm method div[300A,

> 300A,

> com.sap.aii.mappingtool.tf3.rt.Context@1af41af4]</b>>

> Hi Balu,

> >

> > Use the follwing UDF which will return if it is

> > numeric otherwise return 0

> >

> >

   //write your code here
> >  int x = 0;
> > ry{	
> > Integer.parseInt(a);
> > return a;                }	
> > catch(NumberFormatException e){
> >                       return "0";           }

Answers (1)

Answers (1)

Former Member
0 Kudos

Balu,

Check out this thread..

Nilesh