WHENEVER

The WHENEVER statement traps SQL and 4GL errors, warnings, and end-of-data conditions that may occur during program execution.

4GLREF00000191.gif

function is a function name (without parentheses or argument list) to be invoked if the specified exceptional condition occurs.

label is a statement label (in the same program block) to which 4GL transfers program control when the specified exceptional condition occurs. (Statement labels must be declared with the LABEL statement.)

This statement can appear only within a MAIN, REPORT, or FUNCTION program block. It can trap errors, warnings, and the NOT FOUND condition at run time.

The WHENEVER statement must include two items of information:

Some type of exceptional condition

An action to take if the specified exceptional condition is detected

These specifications correspond respectively to the left-hand (conditions) and right-hand (actions) portions of the preceding syntax diagram.

Using WHENEVER is equivalent to including code after every SQL statement, and (optionally) after certain other 4GL statements to take the specified action if the exceptional condition is detected. Without WHENEVER, program execution immediately stops when a run-time error occurs, unless the database is ANSI-compliant.

If you use WHENEVER ERROR with any option but STOP or CONTINUE, 4GL tests for errors by polling the global variable status.

References

CALL

DEFER

FOREACH

FUNCTION

GOTO

IF

LABEL

VALIDATE