Functions in 4GL Programs

In 4GL, a function is a named collection of statements that perform a task.  (In some programming languages, terms like method, subroutine, and procedure correspond to a function in 4GL.) If you need to repeat the same series of operations, you can call the same function several times, rather than specify the same steps for each repetition. This construct supports the structured programming design goal of segmenting source code modules into logical units, each of which has only a single entry point and controlled exit points.

4GL programs can invoke the following types of functions:

·         Programmer-defined 4GL functions

·         4GL built-in functions

·         SQL built-in functions (invoked by SQL statements)

·         C functions

·         ESQL/C functions (if you have ESQL/C modules)

The FUNCTION statement defines a function. Variables that are declared within a function are local to it, but functions that are defined in the same module can reference any module-scope variables that are declared in that module. See the descriptions in the "Programmer-Defined 4GL Functions" section of this volume, and "FUNCTION" in the 4GL Statements volume. The other types of functions that you can call from a 4GL program are briefly discussed on the next pages.