cancel
Showing results for 
Search instead for 
Did you mean: 

UDF help

Former Member
0 Kudos

Hi,

I am writing a udf to assign a specific value when the incoming value is in a specific range.

The udf is

if ((i>=55201) && (i<=59999))

{

return ("X001")

}

if ((i>=65000) && (i<=67999))

{

return ("X002")

}

if ((i>=70000) && (i<=74999))

{

return ("X003")

}

when testing the mapping it is giving the following error:

operator >=cannot be applied to java.lang.String,int.

operator <=cannot be applied to java.lang.String,int.

If the value is between 55201 and 59999, i need to assign new value.

So that I have used >= and <= operators, but it is giving operator error.

Is there anyway to execute this condition.

Experts pls advise.

Thanks in advance..

Bala

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

what is variable i?

If it the input value/argument that is been passed to UDF, then you need to convert it before comparison

UDF by deault takes input as string.

int int_i = Integer.parseInt(i); // i is a parameter to UDF

now you can use code for comparison

Former Member
0 Kudos

Hi Mugdha Kulkarni,

I tried with your tips, but now getting different error;

missing return statement

}

1 error.

Is there anything needs to be included?

Regards

Bala

Former Member
0 Kudos

Hi,

The else part is missing in your UDF.

Try as below

public String check(String a,Container container)
{
int i = Integer.parseInt(a);
if ((i>=55201) && (i<=59999))
{
return ("X001");
}
else if ((i>=65000) && (i<=67999))
{
return ("X002");
}
else if ((i>=70000) && (i<=74999))
{
return ("X003");
}
else
{
return "Invalid";
}

}

Former Member
0 Kudos

Hi Malini,

Thanks a lot, problem solved.

Already given the points.

Regards

Bala

Answers (2)

Answers (2)

santhosh_kumarv
Active Contributor
0 Kudos

Hi,

Within UDF all the Inputs are only of type String. First parse your string input to numeric value and continue coding the UDF.

Your requirement can done in Graphical Mapping itself rather that going with the UDF.

Thanks,

SaNv...

Former Member
0 Kudos

Hi,

Thanks for the immediate response.

Can you pls explain me, how can we do this in graphical mapping?

Regards

Bala

Former Member
0 Kudos

create UDF and add one input parameter to it in UDF (assume param as input )

input is of type string ,so convert the same to int by using

Int i = Integer.parseInt(input);

then your condition specified as it is ..

thats it..

HTH

Rajesh

Former Member
0 Kudos

Graphical mapping

you need to use standard function IF 3 times

IF1 returns false ---> IF2 returns false IF 3

Each of the three IF to be used with functions less,greater,equal, And,Or as per logic and requirement of comparison

Former Member
0 Kudos

>Can you pls explain me, how can we do this in graphical mapping?

by using the standard functions of the "Boolean" function category. (e.g if, ifWithoutElse, ) and the standard functions from "Text" function category (e.g compare, equalsS etc)

but this would kind of text based comparisions.

although you can achieve using graphical mapping, i would recommend a small java udf, where you can have greater control.

thanks,

ganesh(g22sep)

Former Member
0 Kudos

What is the data type of i?

If it is a string value convert to int and then apply the conditons.