User-defined functions are coded in the
declaration portion (
PROC GLOBAL) of an application. Once defined, they can be used anywhere in an application. Functions are used to perform operations that are used in several different places in an application.
Functions are of the form:
return_value = function_name(parameter_list);
Functions may include a list of parameters, which can vary depending on the function call's requirements. This list may be empty (that is, it contains no parameters between the opening and closing parentheses) or it may contain one or more parameters. Each parameter specifies a variable or object that is used by the statements within the function.
Numeric, string, and alphanumeric variables are local to the function. That is, if a variable is passed as an argument, its value in the rest of the application will not be changed by actions within the function (this is called "pass by value"). On the other hand,
objects (such as arrays and file handlers) passed as arguments refer to the source variable and interactions on the variable affect the source variable (this is called "
pass by reference"). If you want to pass a numeric or string variable by reference, you can use the
ref keyword to signify that changes made in the function should affect the source variable.
A user-defined function:
- Returns a single value, either numeric or alphanumeric.
- Can contain CSPro statements and functions, as well as other user-defined functions. If no return value is assigned to the function, the value default (or a blank string) is returned.
The
function statement allows the creation of a user-defined function.
You can use the
invoke function or
Logic.invoke action to call a function with the function name specified only at runtime. Additionally, you can execute user-defined functions while viewing
HTML content by using the
Action Invoker.