cancel
Showing results for 
Search instead for 
Did you mean: 

how to call an UDF from an UDF

Former Member
0 Kudos

HI, in PI7.1 message mapping , I create 2 UDF, myfuntion1, myfunction2.

I want to call myfunction2 from myfunction1.

myfunction1 () {

myfunction2();

}

or

myfunction1() {

Local.myfunction2();

}

All of above compile failed with syntax error, ??? any help

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

HI.

You can try this.

Generated your function in .jar and import your jar in the section Mapping -importedArchives and after that you can you in your UDF

use reference like

Seccion import test1.Functions;

return Functions.returnVal(value);

Former Member
0 Kudos

thanks, but cann't we call one UDF directlly from one UDF as mentioned in

http://help.sap.com/saphelp_nwpi711/helpdata/en/43/991c1f7ee225b3e10000000a1553f7/content.htm

Former Member
0 Kudos

Other option in put your methods in the seccion global.

Click in the button EditJavaSecction -- init()and cleanUp()

And you call them.

Former Member
0 Kudos

Hi,

You can follow luis options if you use xi or pi 7.0. But if you use 7.1 then you can put your udf in a shared folder and then you can access from any mapping. Please check this bills blog on this:

/people/william.li/blog/2008/01/02/sap-pi-71-mapping-enhancements-series-share-user-defined-functions

Regards,

---Satish

Former Member
0 Kudos

Hi

Use like this add the $ at the end.

function1


return function2$(val,container)   -- remember to put all parameters includ the container.

Former Member
0 Kudos

thank you Luis and all.

I did a silly mistake, I missed to pass the container parameter to funtion2.

NOTICE, it does not need a "$" end of the function name.

The following code work now.

UDF1:

function1(para1, container) {

function2(para2, para3, container);

}

UDF2:

function2(para2, para3, container) {

}

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi shiwudao,

You do not have any problem to call a UDF from other UDF. I think when are calling the second UDF you are not passing the correct parameters. Pls, see which parameter are required in the second UDF, then go to first UDF and call it correclty. Take care about UDF`s scope, you are not able to call a "context" UDF" from a "value" UDF.

Regards

Ivan

Former Member
0 Kudos

HI,

Here is the solution:

1. You make sure that the second UDF is being used in the mapping('cause, PI message mapping generator, only compile the used functions).

2. Add to your function the prefix "$".


public string udf1(String value, Container container){
return udf2$(value,container);
}

public string udf2(String value, Container container){
return "Hi:"+value;
}

Regards

Ivan