Using get diagnostics

The get diagnostics statement retrieves error, warning, and informational messages from Client-Library. It is similar to— but more powerful than—the whenever statement because you can expand it to retrieve more details of the detected errors.

If, within a whenever statement, you specify the application to go to or call another application or paragraph, specify get diagnostics in the procedure code, as follows:

err-handler.
 exec sql get diagnostics :num-msgs = number
 end-exec.
 perform varying condcnt from 0 by 1
 until condcnt greater or equal num-msgs
 exec sql get diagnostics exception :condcnt
     :sqlca = sqlca_info end-exec
     display "sqlcode is " sqlcode
     display "message text is " sqlerrmc
 end-perform.