cancel
Showing results for 
Search instead for 
Did you mean: 

UDF not working properly

Former Member
0 Kudos

Hi All

I have writted UDF to check the condition it is working fine in the Eclipse but when i test it in the XI it is not working as expected

The first if condition is not working

Any suggestions

                              if (a.equals("F") && (b  != ("03")))

                              {

                              c="test";

                              System.out.println(c);

                              }

                              else if(a.equals("F") && (b.equals("3")))

                              {System.out.println("PMI");}

 

 

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

                              {

                              System.out.println("FAB");

                              }

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

                              {

                                        System.out.println("MIX");

                              }

 

 

 

                              else

                                                  {

                                        System.out.println("NA");

                                                  }

          }}

Accepted Solutions (1)

Accepted Solutions (1)

former_member184681
Active Contributor
0 Kudos

Hi Sankar,

Simply replace each occurrence of System.out.println("SOMETHING") with result.addValue("SOMETHING") or return("SOMETHING") (depending on the Execution Type of your UDF - single values or all values of context/queue) and it should work as expected.

Also make sure to avoid doubleposting your questions in multiple forums - posting a thread once is enough to receive valuable inputs.

Hope this helps,
Greg

Former Member
0 Kudos

Hi

This is the code the problem is first if condition if i put .equals and != is not working please suggest any other way to do this

String a = BESKZ;

String b = MARC;

String c ="";

if (a.trim().equals("F") &&  (Integer.parseInt(b.trim())!=03))

{

c="POP";

}

  if(a.equals("F") && (b.equals("03")))

{

c ="PMI";

}

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

{

c="FAB";

}

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

{

c="MIX";

}

else

{

c="NA";

}

return c;

former_member184681
Active Contributor
0 Kudos

Try with: if (a.equals("F") && !(b.equals("03")))

Former Member
0 Kudos

It is not working i have passed F and 04 but still it going to else condition

Shabarish_Nair
Active Contributor
0 Kudos

in your code you have used;

(b  != ("03")))

this should ideally be !b.equals("03")

former_member184681
Active Contributor
0 Kudos

This is because you are missing ELSE at the beginning of this line:

  if(a.equals("F") && (b.equals("03")))

Use: else if(a.equals("F") && (b.equals("03"))) there and it should work as you expect.

Regards,
Greg

Former Member
0 Kudos

try this:

if (a.equals("F") && !b.equals("3"))

                              {

                                        return "test";

                              }

                              else if(a.equals("F") && (b.equals("3")))

                              {
                       return "PMI";
                             }

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

                              {

                              return "FAB";

                              }

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

                              {

                                       return "MIX";

                              }

                              else

                                                  {

                                       return "NA";

                                                  }

Former Member
0 Kudos

Hi Thanks

You idea worked but i have doubt how it works correctly in the eclipse

Thanks

Sankar

Former Member
0 Kudos

Hi

Thanks Gloawcki it is now working but i dont know how to reward point in the new sdn can you tell me the procedurce

former_member184681
Active Contributor
0 Kudos

Do you mean how to do it technically? I am not pretty sure, as I did not have a chance to post a thread in the new SCN. But I think you should find some radiobuttons below each answer, to mark this answer as helpful or as correct (one that solved the problem).

Former Member
0 Kudos

Hi

I did not find any thing like that i want to give point to every one who helped me is that any other way to reward point?

Shabarish_Nair
Active Contributor
0 Kudos

you can give points by marking each reply as helpful (5 point) or answered (10 points) and also even click the like button for minor helps (2 points)

Shabarish_Nair
Active Contributor
0 Kudos

just an update on the points system - http://scn.sap.com/docs/DOC-18475

Scroll down to the section How do I award points in Discussions? in the document (scroll down since link will not work)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi

if (a.equals("F") && (b  != ("03")))

Just try this

If (a.equals("F") && b != "03")

Regards,

Krishna

Former Member
0 Kudos

hi Sankar,

Give the first if condition as

if(!("03").equals(b) && "F".equals(a))

Use return not system.out.println, it will not work here.

Former Member
0 Kudos

hi

I tried but still have the same issue i tried in eclipse it is working but not in xi

Former Member
0 Kudos

both String a and String b should be there in function arguments input parameters.

try this:

if ((a.equals("F")) && (!(b.equals("03"))))

and see if it goes to true condition on a=F and b=04.

Shabarish_Nair
Active Contributor
0 Kudos

  if (a.equals("F") && (b  != ("03")))

>>>

check the syntax for this line.

Former Member
0 Kudos

I tried that also hmm no use

Former Member
0 Kudos

hi the syntax is working correctly in eclipse but not in the sap that what wondering me

Former Member
0 Kudos

use return instead of system.out.pritln