FUNCTION

This statement defines a FUNCTION program block.

4GLREF00000058.gif

argument is the name of a formal argument to this function. The DEFINE statement that follows must specify a data type for each argument.

function is the identifier that you declare for this 4GL function.

statement is an SQL statement or other 4GL statement.

A 4GL function is a named block of statements. The FUNCTION statement defines a 4GL function that can be invoked from any module of your program.

The FUNCTION statement has two effects:

To declare the name of a function and of any formal arguments. 4GL imposes no limit on the number or size of formal arguments.

To define the corresponding FUNCTION program block.

The FUNCTION statement cannot appear within the MAIN statement, nor in a REPORT statement, nor within another FUNCTION statement.

If the function returns a single value, it can be invoked as an operand within a 4GL expression. Otherwise, you must invoke it with the CALL statement. An error results if the list of returned values in the RETURN statement conflicts in number or in data types with the RETURNING clause of the CALL statement that invokes the function.

The Prototype of the Function

The FUNCTION statement both declares and defines a 4GL function. The function declaration specifies the identifier of the function and the identifiers of its formal arguments (if any). These specifications are sometimes called the function prototype, as distinct from the function definition:

4GLREF00000147.gif

argument is the name of a formal argument to this function. This can be of any data type of 4GL except ARRAY.

function is the identifier that you declare for this 4GL function.

The FUNCTION Program Block

The statements between the argument list and the END FUNCTION keywords comprise the FUNCTION program block. These statements are executed whenever the function is successfully invoked.

4GLREF00000148.gif

statement is any SQL statement or other 4GL statement (but not FUNCTION, REPORT, MAIN, GLOBALS, nor the report execution statements (NEED, PAUSE, PRINT, and SKIP).

References

CALL

DEFINE

RETURN

WHENEVER