FUNC

A function is a model part that can be parameterized. This model part then can be used several times by calling the function. Just like standard functions these functions all have one Result. Functions can enhance the readability of model documents by removing code fragments that perform simple tasks from the main part of a model document. They can also help to raise the maintainability of model documents by clustering little tasks that depend on external factors. Functions, just as the variables, have to be declared, before they can be used.

Function declaration:

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

Rules:

Rules for the parameter list:

Note

Arrays and MAPs cannot be passed as CONST parameters.

Constant parameters values cannot be changed within the function whereas the values of variable and array parameters can be changed by or in the function. Functions are always used in the context of a formula. Therefore you have to mind the type of the function when applying it.

Note

You cannot use recursive functions.

Use

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.

Definition:

FUNC TEXT amount2 ( CONST NUMBER money)
DO
NUMBER positive := money
TEXT result
IF money < 0
THEN
ASSIGN positive := - money
FI
ASSIGN result := number( positive; 2 )
IF money = 0
THEN
ASSIGN result := "-.-"
ELIF money < 0
THEN
ASSIGN result := result + " negative"
FI
ASSIGN amount2 := result
OD

Note

Note the assignment of result to the name of the function. In this way the result value is returned to the calling environment.

Use:

#
@( amount2( 23.14))
@( amount2( 0))
#

The construction @( ) is used for displaying the result of the function in the result text.

Function versus procedure (FUNC vs PROC)

A function must be used when a return value is expected and needed. For example in an expression.

In this example the build in function uppercases is used to change the text

TEXT initial := "a" 			
TEXT name := "johnson"
#
@(uppercases(initial + " " + name))
#

Note

Note that the function is called in a @( ) construction which means that the value returned by the function is put in the result document directly.

On the other hand, a PROC can be used to separate any part of a model document whether it returns a value or not.