The WHENEVER statement specifies the action to be taken when a specified exception condition occurs.
This statement can only be embedded in an application program. It is not an executable statement. The statement is not supported in REXX.
None required.
>>-WHENEVER--+-NOT FOUND--+--+-CONTINUE---------------------+-->< +-SQLERROR---+ +-+-GOTO--+--+---+--host-label-+ '-SQLWARNING-' | '-GO TO-' '-:-' | '-DO--+-function-name()-+------' +-BREAK-----------+ '-CONTINUE--------'
The function name resolution takes place during the compilation of the C and C++ embedded SQL application. The DB2® precompiler does not resolve the function name.
An SQL statement is within the scope of the last WHENEVER statement of each type that is specified before that SQL statement in the source program. If a WHENEVER statement of some type is not specified before an SQL statement, that SQL statement is within the scope of an implicit WHENEVER statement of that type in which CONTINUE is specified.
If the WHENEVER statement is not used, the default action is to continue processing if an error, warning, or exception condition occurs during execution.
The WHENEVER statement must be used before the SQL statements that you want to affect. Otherwise, the precompiler does not know that additional error-handling code is required for the executable SQL statements. You can have any combination of the three basic forms active at any time. The order in which you declare the three forms is not significant.
To avoid an infinite looping situation, ensure that you undo the WHENEVER handling before any SQL statements are executed inside the handler. You can undo the WHENEVER handling by using the WHENEVER SQLERROR CONTINUE statement.
The WHENEVER statement support for use of the DO function-name(), DO BREAK, or DO CONTINUE syntax is available in Version 9.7 Fix Pack 6 and later.
EXEC SQL WHENEVER SQLERROR GOTO HANDLERR;
EXEC SQL WHENEVER SQLWARNING CONTINUE;
EXEC SQL WHENEVER NOT FOUND GO TO ENDDATA;
/* DO function_name */
EXEC SQL WHENEVER SQLERROR DO perform_error_action();
EXEC SQL WHENEVER SQLWARNING DO perform_warning_action();
EXEC SQL WHENEVER NOT FOUND DO perform_notfound_action();
/* DO BREAK */
EXEC SQL WHENEVER SQLERROR DO BREAK;
EXEC SQL WHENEVER SQLWARNING DO BREAK;
EXEC SQL WHENEVER NOT FOUND DO BREAK;
/* DO CONTINUE */
EXEC SQL WHENEVER SQLERROR DO CONTINUE;
EXEC SQL WHENEVER SQLWARNING DO CONTINUE;
EXEC SQL WHENEVER NOT FOUND DO CONTINUE;