Try OpenEdge Now
skip to main content
SQL Reference
ESQL Reference : Embedded SQL : ESQL elements and statements : WHENEVER
 
WHENEVER
Specifies actions for three SQL run‑time exceptions.

Syntax

WHENEVER
{ NOT FOUND | SQLERROR | SQLWARNING }
{ STOP | CONTINUE |{ GOTO | GO TO }host_lang_label} ;

Parameters

{ NOT FOUND | SQLERROR | SQLWARNING }
*The NOT FOUND exception is set when sqlca.sqlcode is set to SQL_NOT_FOUND.
*The SQLERROR exception is set when sqlca.sqlcode is set to a negative value.
*The SQLWARNING exception is set when sqlca.sqlwarn[ 0 ] is set to W after a statement is executed.
{ STOP | CONTINUE | GOTO | GO TO }host_lang_label}
*The STOP exception results in the ESQL program stopping execution.
*The CONTINUE exception results in the ESQL program continuing execution. The default exception is to CONTINUE.
*GOTO | GO host_lang_label results in the ESQL program execution to branch to the statement corresponding to the host_lang_label.

Notes

*You can place multiple WHENEVER statements for the same exception in a source file. Each WHENEVER statement overrides the previous WHENEVER statement specified for the same exception.
*Correct operation of a WHENEVER statement with a GOTOhost_language_label or a GO TOhost_language_label is subject to the scoping rules of the C Language. The host_language_label must be within the scope of all SQL statements for which the action is active. The GO TO or GOTO action is active starting from the corresponding WHENEVER statement until another WHENEVER statement for the same exception, or until end of the file.

Example

/*
** Name WHENEVER routine to handle SQLERROR condition.
*/
EXEC SQL WHENEVER SQLERROR GOTO mainerr ;
/*
** Name WHENEVER routines to handle NOT FOUND and SQLERROR
*/
EXEC SQL WHENEVER SQLERROR GOTO nodyn ;
EXEC SQL WHENEVER NOT FOUND GOTO nodyn ;
* Authorization
* Related statements