7. Understanding Database Procedures, Sessions, and Events : Database Events : Database Event Statements : Whenever Dbevent Statement
 
Share this page                  
Whenever Dbevent Statement
To use the WHENEVER DBEVENT statement, your application must include an SQLCA. When a database event is added to the database event queue, the SQLCODE variable in the SQLCA is set to 710 (also the standalone SQLCODE variable is set to 710; SQLSTATE is not affected). However, if a query results in an error that resets SQLCODE, the WHENEVER statement does not trap the database event. The database event is still queued, and your error-handling code can use the GET DBEVENT statement to check for queued database events.
To avoid inadvertently (and recursively) triggering the WHENEVER mechanism from within a routine called as the result of a WHENEVER DBEVENT statement, your database event-handling routine must turn off trapping:
main program:

exec sql whenever dbevent call event_handler;

...

event_handler:

/* turn off the whenever event trapping */
     exec sql whenever dbevent continue;

exec sql inquire_sql(:evname=dbeventname...);

process events
return