FUNC

Functions are code fragments that can perform a parameterized calculation and return a single value. You can use functions anywhere where a value is expected, increasing the maintainability of Master Templates.

The following is an example of the function declaration.

FUNC TYPE function_name ( parameter_1;parameter_2;..., optional parameter 
list) 
DO 
			<Template scripting part of a model with declarations> 
			ASSIGN function_name := result_of_function 
OD 

The requirements for creating a function are as follows:

  • The function_name must start with a lowercase character and is limited to lowercase characters, digits, and underscores. Spaces are not allowed.
  • The TYPE the result of the function; NUMBER, TEXT of BOOL.
  • The result of a function is returned by assigning it to function_name.
  • The parameter list is optional.

The requirements for the parameter list are the following:

  • Parameters must be separated with a semicolon.
  • A parameter can be one of four types: CONST TYPE name (a parameter cannot be changed in the PROC); TYPE name (a variable as parameter); ARRAY TYPE name (an array as parameter); MAP TYPE name (a map as parameter).
  • The parameter name (parameter_1) must start with a lowercase character and is limited to lowercase characters, digits, and underscores. Spaces are not allowed.
  • TYPE, the following types are possible: TEXT, NUMBER, BOOL, and FIELDSET. TYPE can also be a previously defined DATASTRUCTURE. For more information on the types of parameters, see Types.

Constant parameters values cannot be changed in the function. The values of variable and ARRAY parameters can be changed in the function. Functions are always used in the context of a formula.

ARRAY and MAP cannot be passed as CONST parameters.

FIELDSET and Data Structures cannot be used as an ARRAY or MAP parameter or passed as a CONST parameter.

You cannot use recursive procedures.

The following is an example of a function call.

function_name ( parameter_1; parameter_2; ... )

The number of parameters and their types in the actual parameter list must be the same as the parameter list in the declaration of the function. Parameters can only be passed to a function when a parameter list is declared in the function declaration.