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 parameter list, 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, array, list, or file handler 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 a parameter, 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, arrays, lists, and file handlers passed as parameters refer to the source variable and interactions on the variable affect the source variable (this is called "pass by reference").
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.
statement allows the creation of a user-defined function.