FUNCTION

From Recital Documentation Wiki
Revision as of 14:59, 17 March 2009 by Yvonnemilne (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

FUNCTION

Class

Applications


Purpose

Declare a User Defined Function (UDF)


Syntax

FUNCTION <expC>[(<parameter-list>)]


See Also

ALIAS, DO, ENDFUNC, KEYWORD, LINK, PARAMETERS, PARAMETERS(), PCOUNT(), PRIVATE, PROCEDURE, PUBLIC, RETURN, SET COMPATIBLE, SET PROCEDURE


Description

A FUNCTION <expC> command is used to declare a User Defined Function (UDF). Recital/4GL UDFs can be used not only in programs, but also in the Applications Data Dictionary, the Report Writer and wherever a standard Recital/4GL function can be used.

A UDF can have a variable number of parameters passed to it. These are assigned to private variables in the optional PARAMETERS statement, which if used, must appear following the FUNCTION statement and before any other executable statement. If a PARAMETERS statement is present, then at least one parameter must be specified with the UDF call. The PCOUNT() function can be used to determine how many actual parameters were specified.

The functions in a procedure library file are made known to the Recital/4GL by using the SET PROCEDURE TO command. Functions can be included in program files, as well as in procedure library files. If a function is included in a program file, then it must be defined before it is used.

The FUNCTION command is terminated with a RETURN statement. The RETURN statement can optionally have an expression specified. If none is specified then .F. is returned. Other RETURN statements may be included in the syntax following a FUNCTION command, provided that they are properly nested between IF...ENDIF, DO WHILE...ENDDO, or DO CASE...ENDCASE. The Recital/4GL function names can be a maximum of 32 characters in length, and must begin with a letter or underscore, followed by any combination of letters (A-Z), digits (0-9), and underscores (_).

To execute a UDF, name it in an expression, followed by parameters in round brackets. It will behave just like any standard Recital/4GL function.

There is no limit to the number of functions that can be declared in the Recital/4GL. The commands LIST PROCEDURE or DISPLAY PROCEDURE will let you see all currently active functions and procedures.

If SET COMPATIBLE is set to VFP or CLIPPER5, the FUNCTION command can also include the parameter list declaration, instead of requiring a separate PARAMETERS statement. The parameters should be listed in comma-separated format within parentheses after the function name, e.g.

function myfunc(para1, para2, para3)

If SET COMPATIBLE is set to VFP, the FUNCTION declaration can be terminated with an ENDFUNC command rather than a RETURN. It will also be terminated when another PROCEDURE or FUNCTION command is reached.


Example

// Function to return product of two numbers
function atimesb
parameters a, b
result=a*b
return result
? atimesb(5,10)
        50


Products

Recital Database Server, Recital Mirage Server, Recital Terminal Developer