8. OpenSQL Statements : Whenever
 
Share this page                  
Whenever
Valid in: ESQL
The WHENEVER statement enables your application to handle error and exception conditions arising from embedded OpenSQL database statements. The WHENEVER statement stipulates that a specified action be performed when a specified condition occurs. The WHENEVER statement detects conditions by checking SQLCA variables, so an SQLCA must be included in your program before you issue the WHENEVER statement.
After a WHENEVER has been declared, it remains in effect until another WHENEVER is specified for the same condition. Since WHENEVER is a declarative and not an executable statement, its physical location in the program's source code, rather than its sequence in the program's execution, determines its scope.
WHENEVER statements can be repeated for the same condition and can appear anywhere after the INCLUDE SQLCA statement.