WARNING! Although SQLSTATE is preferred over SQLCODE and SQLCA, this version of the precompiler supports only SQLCODE. A future version will fully support both SQLCA and SQLSTATE.
SQLSTATE is a status parameter. Its codes indicate the status of the most recently attempted statement—either the statement completed successfully or an error occurred during the execution of the statement.
The following example illustrates a declaration of SQLSTATE:
WORKING-STORAGE SECTION.
01 SQLSTATE PIC x(5)
. . .
exec sql whenever sqlerror perform ERR-PARA
end-exec
. . .
ERR-PARA.
    IF  sqlstate = "ZD000" or
         sqlstate = "ZE000" or
         sqlstate = "ZF000" or
         sqlstate = "ZG000" or
         sqlstate = "ZH000" 
         DISPLAY "Unexpected results were ignored"
     ELSE 
        IF sqlstate = "08001" or sqlstate = "08000"
              DISPLAY "Connection failed-quitting"
              STOP RUN
         ELSE 
             DISPLAY "A non-results, non-connect
             — error occurred"
        END_IF
    END_IF
Table 3-3 lists SQLSTATE values:
Value  | 
Description  | 
|---|---|
00XXX  | 
Successful execution  | 
01XXX  | 
Warning  | 
02XXX  | 
No data exists; no rows affected  | 
Any other value  | 
Error  |