External Function Declarations
External function declarations are allowed in application classes, in the global and component variable declarations, after the class declaration (after the end-class statement), and before the method definitions. For example:
import SP:Record;
class Person extends SP:Record
method Person(&pid As string);
method getPerson() Returns Record;
method getUserName() Returns string;
private
instance Record &recPerson;
end-class;
Declare Function getUserName PeopleCode FUNCLIB_PP.STRING_FUNCTIONS FieldFormula;
method Person
/+ &pid as String +/
%Super = create SP:Record(Record.SPB_PERSON_TBL);
&recPerson = %Super.getRecord();
&recPerson.PERSON_ID.Value = &pid;
end-method;
method getPerson
/+ Returns Record +/
Return &recPerson;
end-method;
method getUserName
/+ Returns String +/
Local string &formattedName;
&formattedName = getUserName(&recPerson.PERSON_ID);
Return &formattedName;
end-method;When application class properties and instance variables are used as the argument to functions or methods, they are always passed by value, never by reference. This means that the called function or method cannot change the value of the property or instance variable. If you want a function call to change a property or instance variable, use a local variable in the call and then assign the property or instance variable after the call.
Suppose you have the following class and you want to call Meth2 in the body of Meth1, passing it MyProp:
class MyClass
property number MyProp;
method Meth1();
method Meth2(&i as number out);
end-class;The following PeopleCode fails with a compile-time error:
method Meth1
Meth2(%This.MyProp); /* error - field or temp name required. */
Meth2(&MyProp); /* error - field or temp name required. */
end-method;The following PeopleCode is valid:
method Meth1
/* Assignment needed if &i is input as well as output in Meth2. */
local number &Var = %This.MyProp;
Meth2(&Var);
%This.MyProp = &Var;
end-method;Note:
You call a Java program from an Application Class the same way you do using any other PeopleCode program, that is, by using one of the existing Java class built-in functions.