cancel
Showing results for 
Search instead for 
Did you mean: 

simple UDF

Former Member
0 Kudos

why do following UDF giving error. It is expecting return statement from else part. I donot want else part of If stmt Iam writing.

<i>public String GroupTest(String a,Container container){

if (a.equals("ExportOne")) return "One";

if (a.equals("ExportTwo")) return "Two";

if (a.equals("ExportThree")) return "Three";</i>

What is problem with above UDF?. I want If statements without else part. Can someone please help me.

Im writing this as part of message splits. So please do not suggest to use fixvalues mapping or something else. I am just looking for multiple if statements without else part.

Thanks

RK

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Ram,

Any java function should return some value in ur case as all the return statements are with in IF statement so code will not compile.

So put a dummy return statement at the end.

return " ";

Regards,

Kavitha

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Ram,

the method has to return something in every case so here it is claiming a missing

...
else
 return "something";

Why don't you go for something like:


return a.replaceFirst("Export","");

Regards,

Sergio

MichalKrawczyk
Active Contributor
0 Kudos

hi,

can you try this:

if (a.equals("ExportOne"))

{

return "One";

}

else if (a.equals("ExportTwo"))

{

return "Two";

}

else

{

return "nothing";

}

Regards,

michal

Former Member
0 Kudos

Michal,

thanks but I donot want else part. basically I donot like UDF return 'nothing' as in your example. Any other suggestions?. I want multiple if statements without else part. Thx

Former Member
0 Kudos

Ram,

for the signature of the method it is necessary to return something in any case (ExportFour), so the else is necessary.

Otherwise you can go for the solution I proposed.

Sergio

Former Member
0 Kudos

Ram,

U just put a dummy return at the end as I have already suggested

get back if it does nt work

Kavitha

Former Member
0 Kudos

ur code should look like

public String GroupTest(String a,Container container){

if (a.equals("ExportOne")) return "One";

if (a.equals("ExportTwo")) return "Two";

if (a.equals("ExportThree")) return "Three";

return " ";

}

ranjit_deshmukh
Active Participant
0 Kudos

Ram,

this is very strange req. that you dont want else stmt

but Kavita's sol will do

try:

if (a.equals("ExportOne")) return "One";

if (a.equals("ExportTwo")) return "Two";

if (a.equals("ExportThree")) return "Three";

return " ";

Ranjit

Former Member
0 Kudos

You guys are awesome. Thank you for quick turnaround. Many of you answered perfectly and the explantion of Kavitha ( First in answering chain ) really helps to find the reason behind not having else part. Thanks again.

ranjit_deshmukh
Active Participant
0 Kudos

Hi Ram,

the problem you are facing is may be because

the input to the udf isnt one of the ExportOne,ExportTwo or ExportThree

please make it sure that you are sending them

otherwise it wo'nt ask for 'else'

and see to it that udf must return something.

Ranjit

Former Member
0 Kudos

Hi,

even before testing the function when I do check mapping its giving me error. i'm giving the same value as shwon in the if statement