cancel
Showing results for 
Search instead for 
Did you mean: 

How to assign the null values in UDF?

Former Member
0 Kudos

Hi Guys,

I have a UDF as below. How to handle the null values in the UDF? I tried a.equals("") but it is throwing errors.

int b = Integer.parseInt(a);

if(b==0) {

 return "1" ;  }

 else if(b==104) {

 return "5" ;  }

else return "2" ;

any help would be appreciated.

Thanks,

Raj

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Try this: "".equals(a)

Best Regards,

Pedro Pereira

Former Member
0 Kudos

Hi Pedro,

I tried that and i am getting the following error

Exception:[java.lang.NumberFormatException: For input string: ""]

Thanks,

Raj

Former Member
0 Kudos

Hi,

Well try this, a.equals(null)

Therefore, it is odd that you are getting that error, java.lang.NumberFormatException: For input string: "", in equals fuction. It is an exception for Integer.parseInt function.

Best regards,

Pedro Pereira

Former Member
0 Kudos

Is variable a, a string or an integer?

Best regards,

Pedro Pereira

Former Member
0 Kudos

Hi Pedro,

a is string and b is integer.

Thanks,

Raj

Former Member
0 Kudos

Hi Pedro,

If i use this condition at the begining it is working fine. "".equals(a) also works fine. If i use the condition later it is always taking the b value.

if (a.equals("")) return "1";

int b = Integer.parseInt(a);

if(b==0) {

return "1"; }

else if(b==104) {

return "5" ; }

else return "2" ;

I appreciate the help for all of you.

Thanks,

Raj

Former Member
0 Kudos

Hi Pedro,

a.equals(null) dosent work. a is string not integer.

a.equals("") and ".equals(a) works and they have to be at the begining.

Thanks,

Raj

Answers (6)

Answers (6)

Former Member
0 Kudos

Have you tried using IsNull(a) ?

Former Member
0 Kudos

Hi Guys,

I have resolved the problem by using the standard function and UDF. I will try these options as well in the UDF and i will update the thread.

Source -- If then Else -- has null value then map it to constant 1

else use the UDF to map the other values.

I will work on the above options and let you know.

Thanks a lot

Raj

Former Member
0 Kudos

try this :

if (a.length() > 0) {

int b = Integer.parseInt(a);

if(b==0) {

return "1" ; }

else if(b==104) {

return "5" ; }

} else

return "2" ;

Former Member
0 Kudos

Hi Guys,

I tried all the variants and they r not working and i have looked at the values by displaying the queue.

I have a single value coming into the source field and the values are as below. The source field in this case dosent has any values and it is blank

---> SUPPRESS

-


> 0

-


> 0 Greyed out

any help would be appreciated

Thanks,

Raj

former_member307485
Active Participant
0 Kudos

Hi,

How about this

b.equals(constant[0])

Regards,

Divya

Shabarish_Nair
Active Contributor
0 Kudos

if null means that in the queue you find the value in suppress then your check should be ideally

a[index].equals(ResultList.SUPPRESS)

try that.

former_member200962
Active Contributor
0 Kudos
I tried a.equals("") but it is throwing errors.

try this format if (a==null)

former_member581827
Participant
0 Kudos

Hi,

Have you tried using a.equals("").

Regards,

Chandra.

former_member200962
Active Contributor
0 Kudos

yes he has tried it...check the Q

former_member732072
Active Participant
0 Kudos

Hi Raj,

Did you try b==null or b=="" also b==''

Please check it and see if it works.

Best Regards

Edited by: Prakash Bhatia on May 13, 2009 5:09 AM