Release 10.1A: OpenEdge Data Management:
SQL Reference

> ## WHENEVER

> Specifies actions for three SQL run-time exceptions.

> #### Syntax

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

> `{ 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.
> Examples

>     /*
>     **  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 ;

> #### 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 `GOTO` `host_language_label` or a `GO TO` `host_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.

> ##### Authorization

> None

> ##### Related statements

> FETCH

Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095