cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with the userdefined function

Former Member
0 Kudos

Hi Experts,

Simple userdefined function:

public String ro(String a, Container container) {

if (a.length() == 0)

return "No Value";

}

When I tried to test message mapping with & without the input <b>a</b> value, I am getting the below error. Could you please tell me, what mistake I am doing here.

Source code has syntax error: C:/usr/sap/PI7/DVEBMGS01/j2ee/cluster/server0/./temp/classpath_resolver/Mapf41537902ae911dcb8f1000c29643148/source/com/sap/xi/tf/_MM_RESPONSE_.java:78: missing return statement } ^ 1 error

Regards

Sara

Accepted Solutions (1)

Accepted Solutions (1)

former_member192892
Active Contributor
0 Kudos

Please give the return statement outside the if segment. Use a String object to store the output you desire like

public String ro(String a, Container container) {

String output = "";

if (a.length() == 0)

output = "No Value";

}

else

{

output = a;

}

return a;

}

former_member192892
Active Contributor
0 Kudos

I'm sorry its return output;

Answers (3)

Answers (3)

justin_santhanam
Active Contributor
0 Kudos

public String ro(String a, Container container) {

String res;

if (a.length() == 0)

res="yes";

else

res="no";

return""res"";

Please try the above, if it works I'll tell u the problem why it doesn't works for u.

Best regards ,

raj.

Former Member
0 Kudos

Hi Raj,

It works fine as per your code, but I don't want to have else part. Without else part its not working. Is there any way to eliminate else part?

Regards

Sara

justin_santhanam
Active Contributor
0 Kudos

Try this ,

public String ro(String a, Container container) {

String res="";

if (a.length() == 0)

{

res="yes";

}

return""res"";

Try the above sara, and lemme know.

Best regards,

raj.

Former Member
0 Kudos

Hi Varun,

String output = "";

The above line solved my problem.

Raj,

Yes, I have tried the same. It works fine now.

Thanks a lot.

Sara

Message was edited by:

Sara D

MichalKrawczyk
Active Contributor
0 Kudos

Hi,

no need to use UDF here:

just use those sntadard functions:

<b>length</b> - and <b>if</b>

http://help.sap.com/saphelp_nw04/helpdata/en/43/c4cdfc334824478090739c04c4a249/content.htm

lenght to check the lenght and if to return your value

in case it's length = 0

Regards,

michal

-


<a href="/people/michal.krawczyk2/blog/2005/06/28/xipi-faq-frequently-asked-questions"><b>XI / PI FAQ - Frequently Asked Questions</b></a>

Former Member
0 Kudos

Try making the function as context

and change the UDF to

if(a.length>0)

{

for(int i=0;i<a.length;i++)

{

if(a<i>.length()==0)

{

result.addValue("NoValue");

}

}

Mudit