Retrieves error, warning, and informational messages from Client-Library.
get diagnostics {:hv = statement_info [, :hv = statement_info]...| exception :condition_number :hv = condition_info [, :hv = condition_info]...} end-exec
The keyword number is currently the only supported statement_info type. It returns the total number of exceptions in the diagnostics queue.
Any one of the keywords sqlca_info, sqlcode_number, and returned_sqlstate.
EXEC SQL BEGIN DECLARE SECTION END-EXEC.
01 NUM-MSGS PIC S9(9) COMP.
01 CONDCNT PIC S9(9) COMP.
EXEC SQL END DECLARE SECTION END-EXEC.
...
EXEC SQL GET DIAGNOSTICS :NUM-MSGS = NUMBER END-EXEC.
MOVE 1 TO CONDCNT.
PERFORM GET-DIAG-PARA UNTIL CONDCNT > NUM-MSGS.
...
GET-DIAG-PARA.
EXEC SQL GET DIAGNOSTICS EXCEPTION
:CONDCNT :SQLCA = SQLCA_INFO END-EXEC
DISPLAY "DIAG. SQLCODE = ",SQLCODE
DISPLAY "DIAG. MESSAGE = ",SQLERRMC
ADD 1 TO CONDCNT.
END-GET-DIAG-PARA.
Many Embedded SQL statements are capable of causing multiple warnings or errors. Typically, only the first error is reported using SQLCODE, SQLCA, or SQLSTATE. Use get diagnostics to process all the errors.
You can use get diagnostics, which is the target of the call, perform, or go to clause of a whenever statement, in the code.
You can use get diagnostics after a statement for which you want to retrieve informational messages.
whenever