cancel
Showing results for 
Search instead for 
Did you mean: 

SAP PI - UDF

deva_gembali2
Participant
0 Kudos

Dear Experts,

   How to write java code (udf) for below requirement?

For example, in source file, Brand = 'BK' and customer code = '5123' (starts with 5 ) then print Value "X" else value "Y".

Thank you.

Deva

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

In Message Mapping you can handle with standar functions.

Otherwise you can check this javacode

String sResult = null;

if(Brand.equalS("BK") && CustomerCode.startsWith("5"))

   result = "X";

else

   result = "Y";

return result;

Regards

deva_gembali2
Participant
0 Kudos

HI Luis,

  Thank you. but my code gives small syntax error as  below.

if (Brand.equalsIgnoreCase ("BK") && CustNo.startsWith("5")){

return "3299970";

} else {

return "3299971";

}else if (Brand.equalsIgnoreCase ("DQ") && CustNo.startsWith("5")){

return "3299972";

} else {

return "3299973";

}else if (Brand.equalsIgnoreCase ("SW") && CustNo.startsWith("5")){

return "3299974";

} else {

return "3299975";

}else if (Brand.equalsIgnoreCase ("SZ") && CustNo.startsWith("5")){

return "3299976";

} else {

return "3299977";

}else if (Brand.equalsIgnoreCase ("PZ") && CustNo.startsWith("5")){

return "3299978";

} else {

return "3299979";

}else (Brand.equalsIgnoreCase ("CF") && CustNo.startsWith("5")){

return "3299980";

} else {

return "3299981";

}

Former Member
0 Kudos

Hi.

According you code , many sentence else without if.

Could you clarify your request.?

deva_gembali2
Participant
0 Kudos

I am getting syntax error to above code.

Former Member
0 Kudos

Can you clarify your logic

For example:

If, Brand = 'BK' and customer code = '5123' (starts with 5 ) then print Value "3299971" else value "Y then ...etc

The sintax is incorrect because always return else condition.

for example return "3299971"; return "3299973";return "3299978";

if (Brand.equalsIgnoreCase ("BK") && CustNo.startsWith("5")){

return "3299970";";

}else if (Brand.equalsIgnoreCase ("DQ") && CustNo.startsWith("5")){

  return "3299972";


Answers (1)

Answers (1)

anand_shankar10
Active Participant
0 Kudos

Dear Deva,

Though your query has been answered but for your requirement you could always use standard node functions.

You can achieve your reqrmnt using EqualS, AND and IfThenElse function and its always preferred to use node over UDF.

Regards

Anand

anand_shankar10
Active Participant
0 Kudos

Graphical Mapping snapshot..

deva_gembali2
Participant
0 Kudos

Dear Anand,

    I understood your query and your graphical mapping and perferctly correct.

In my requirement, i have to follow 10 times same mapping as you shown me in once.

So, there is no space for me .So i wrote UDF.

Deva