Skip to Content
avatar image
Former Member

UDF Mapping Error... Simple code

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

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

13 Answers

  • Best Answer
    avatar image
    Former Member
    Dec 06, 2006 at 12:22 PM

    Thanks Sergio you are a genious

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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Dec 06, 2006 at 12:13 PM

    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?

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Dec 06, 2006 at 11:56 AM

    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 😊

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      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

  • avatar image
    Former Member
    Dec 06, 2006 at 12:11 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Dec 06, 2006 at 11:56 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Dec 06, 2006 at 11:57 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Dec 06, 2006 at 12:05 PM

    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?

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      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

  • avatar image
    Former Member
    Dec 06, 2006 at 12:06 PM

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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Dec 06, 2006 at 12:07 PM

    I just tried your suggestion

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

    return "yes";

    and it still says missing return statement?

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Dec 06, 2006 at 12:10 PM

    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"?

    Add comment
    10|10000 characters needed characters exceeded