function 『return_type』 function_name(『parameter1_type, parameter1_name, ..., parameterN_type, parameterN_name』)
『function_name = return_value;』
statement defines a user-defined function
with the name function_name
. Once defined, the function can be called in other user-defined functions or in procedures throughout your application.
Numeric expressions, alphanumeric and string expressions, arrays, lists, file handlers, and function pointers can be passed to a user-defined function as parameters. These parameters are defined by specifying the variable type (e.g., parameter1_type) and the name of the variable (e.g., parameter1_name). If no type is specified, the variable will be considered numeric.
The names used in the parameter list of a function are local to the function. They may not be the same as names that are defined in any dictionary or in PROC GLOBAL
, but the names can be reused in other functions or procedures.
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").
Other than arrays, parameters are defined the same way you would in other parts of logic. However, with arrays, you do not define the size of the array because the array will match the size of the array passed as an argument. By default, an array is one-dimensional. To specify more than one dimension, use parentheses with the number of dimensions specified using commas. For example, a three-dimensional array must include (,,)
after the parameter name. Within the function, the function length
returns the dimension sizes of the passed array.
Functions always return a value, either a numeric, alphanumeric, or string value. If return_type
is not specified, the function will by default return a numeric value. To assign the function's return value, assign a value to function_name
. If no return value is specified, the value default
or a blank string is returned, depending on the return type. The return value can also be specified using the exit