FUNCTION


Identifies a user-defined function which can be invoked by other jBC programs. Arguments to the function can optionally be declared.

 

COMMAND SYNTAX

FUNCTION name {({MAT} variable, {MAT} variable...) }

 

SYNTAX ELEMENTS

name is the name by which the function is invoked.

variable is an expression used to pass values between the calling program and the function.

NOTES

The FUNCTION statement is used to identify user-written source code functions. Each function must be coded in separate records and the record Id must match that of the Function Name, which in turn should match the reference in the calling program.

The optional comma separated variable list can be a number of expressions that pass values between the calling programs and the function. To pass an array the variable name must be preceded by the MAT keyword. When a user-written function is called, the calling program must specify the same number of variables as are specified in the FUNCTION statement.

An extra 'hidden' variable is used to return a value from the user-written function. The value to be returned can be specified within the Function by the RETURN (value) statement. If the RETURN statement is used without a value then by default an empty string is returned.

The calling program must specify a DEFFUN or DEFB statement to describe the function to be called and the function source must be cataloged and locatable similar to subroutines.

EXAMPLE

FUNCTION MyFunction(A, B)
    Result = A * B
RETURN(Result)


jBC