cancel
Showing results for 
Search instead for 
Did you mean: 

UDF Mapping Error... Simple code

Former Member
0 Kudos

I am attempting to try a simple UDF

if (String a == String b || String a == String c)

return "yes";

however I get the following error...

Source code has syntax error:

/usr/sap/CXD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map03a9a9e0852011dbaae9000d60de069c/source/com/sap/xi/tf/_MM_Source_Target_.java:39: ')' expected

if (String a == String b || String a == String c)

^

1 error

Now clearly I am missing ')' somewhere but I dont understand where...

I am trying to do a simple if String 1 is equal to String B or String a is equalt to String c then result is yes.

Can some one let me know where Im going wrong

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Thanks Sergio you are a genious

ok is there like a dictionary where I can find all of these values?

Former Member
0 Kudos

Hi alex,

thanks.......

Have a look at this

http://help.sap.com/saphelp_erp2005vp/helpdata/en/22/e127f28b572243b4324879c6bf05a0/frameset.htm

Happy your problem is solved,

Regards,

Sergio

Former Member
0 Kudos

Alex,

I think you could also need java api (list of standard objects and methods for java developments) : http://java.sun.com/j2se/1.4.2/docs/api/

Have a look at object String and it's methods for example.

Regards,

Sergio

PS: do not forget to mark the problem as solved

Answers (12)

Answers (12)

Former Member
0 Kudos

Hi

<i>2. How do I return one value if condition is met but not map the target field at all if condition is not met. (it is ok to say no or blank but sometimes you just don't want a target field populated at all if conditions are not met)</i>

For this you can use bult in IfWithoutElse function, so you no need to put else case

Regards,

Sai

Former Member
0 Kudos

Ok it seems to work now... Problem with source XML...

But last questions....

1. Why use methods as oppose to operators? What if I need to say is a>b or a>=b how would I do that.... is there a methods dictionary?

2. How do I return one value if condition is met but not map the target field at all if condition is not met. (it is ok to say no or blank but sometimes you just don't want a target field populated at all if conditions are not met)

Former Member
0 Kudos

Alex,

See the signature of the UDF.

It has to necessaily retun something.

May be if false

return"";

Empty String.

Regards,

Sudharshan

Former Member
0 Kudos

Ok adding the else seemed to work yet my target field didn't get mapped with yes or no?

Why is this?

I want it to map yes if conditoions are met and not map at all if conditions are not met?

Former Member
0 Kudos

Have you tried returning the constant ResultList.SUPPRESS;

I think it coul work

Regards,

Sergio

Former Member
0 Kudos

Alex,

this is the way java works, if you have to compare a String <b>Object</b> you have to user the method equal, instead for a simple type like int (<b>not an object</b>) you use operators.

Kind Regards,

Sergio

Former Member
0 Kudos

Alex,

let me know if it works, i cannot try it at the moment but I am curious!!

Regards,

Sergio

Former Member
0 Kudos

Hi

if ( a.equals(b) || a.equals(c))

return "yes";

else

return "no";

or

if ( a.equals(b) || a.equals(c))

return "yes";

return "no";

Both works fine

Regards,

Sai

Former Member
0 Kudos

there is no else branch....

aahhh should I add an else branch anyway so to complete the scenario?

How could I return "Do not Map"?

Former Member
0 Kudos

I just tried your suggestion

if ( a.equals(b) || a.equals(c))

return "yes";

and it still says missing return statement?

Former Member
0 Kudos

Also what if I wanted to say not equal to or greater than etc..

Former Member
0 Kudos

12:02:11 Start of test

Source code has syntax error:

/usr/sap/CXD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map9c1db850852111dba2d2000d60de069c/source/com/sap/xi/tf/_MM_Source_Target_.java:42: missing return statement

}

^

1 error

12:02:15 End of test

Ok I got a new error.... this was before I read your above posts but I was wandering for my information if someone could tell me where I went wrong....

Why there is the return statement missing?

Also why should I not use operators.... I am new to java so just trying to understand... So why methods and not operators?

Former Member
0 Kudos

I think you should also add a return statement in the else branch.

if ( a.equals(b) || a.equals(c)){

return "yes";

}else{

return "no";

}

Regards,

Sergio

Former Member
0 Kudos

Hi ,

if you see first statement of udf it will be like public String test(String a,Container container)

String after public means the function should return String value thats why you are getting error.

Thanks,

Tuhin

Former Member
0 Kudos

Alex,

Hope a,b,c or inputs to the UDF..

By default a,b,c are names of parameter to the UDF.

use different names for local variables other than a,b,c etc

Regards,

Sudharshan

Former Member
0 Kudos

Hi,

To compare two strings you should use equals method present inside String class.You should not use equals operator.

For example a.equals(b).

The equals method will return a true if both strings are equal.

Regards,

Sudheer.

Former Member
0 Kudos

String a;

String b;

String c;

if ( a.equals(b) || a.equals(c))

return "yes";

Regards,

Sergio

PS: a,b,c must be inputs of your UDF

Former Member
0 Kudos

Hi Alex,

You can use....

if (a.equlasIgnorecase(b) || a.equlasIgnorecase(c))

When you want the check to case insensitive.

or when the check as to be case sensitive, then you can follow what Sergio as suggested....

Regards,

Abhy