Every executable SQL statement in DB2 for z/OS comes back with two status values: a signed integer SQLCODE and a five-character SQLSTATE. This page is how to read them, how positive codes differ from negative ones, how GET DIAGNOSTICS exposes the same numbers, and where IBM publishes the official text. Later pages in this section walk individual codes.
Db2 sets both after the statement, whether you INCLUDE SQLCA or declare stand-alone SQLCODE and SQLSTATE with STDSQL(YES). COBOL PIC S9(9) COMP for SQLCODE is a signed binary fullword—do not store it in an unsigned display field that drops the minus.
| SQLCODE | Meaning |
|---|---|
| 0 (000) | Success. If SQLWARN0 is W, success with a warning flag set. |
| +100 | No data. SQLSTATE 02000. FETCH past last row, empty SELECT INTO, searched UPDATE/DELETE with no match. |
| Other + | Success with a warning. Examples: +802 arithmetic exception in SELECT list, +222 cursor hole. |
| Negative | Unsuccessful. Do not assume rows were fetched or changed. |
| Class | Meaning |
|---|---|
| 00 | Success (00000). SQL PL: not NOT FOUND, not warning, not exception. |
| 01 | Warning. SQLWARNING handlers. Example 01519 for +802. |
| 02 | No data. NOT FOUND. 02000 with +100. |
| Other | Exception (syntax 42, integrity 23, deadlock 40, resource 57, …). |
Read a dump in this order: SQLCODE (what happened), SQLSTATE (which standard class), SQLERRMC tokens (which object), SQLERRD(3) or GET DIAGNOSTICS DB2_REASON_CODE (why, for lock and resource failures), then the IBM message text.
1234567891011121314EVALUATE SQLCODE WHEN 0 IF SQLWARN0 = 'W' PERFORM LOG-WARNING END-IF WHEN +100 PERFORM NOT-FOUND-PATH WHEN OTHER IF SQLCODE > 0 PERFORM LOG-WARNING ELSE PERFORM SQL-ERROR-PATH END-IF END-EVALUATE.
A positive SQLCODE means Db2 finished the statement in a way that still counts as successful execution, except that +100 means “success, but no row.” Host variables from a FETCH that got +100 are undefined for that fetch—do not use them. Host variables from a FETCH that got +802 may contain good columns and null indicators of -2 on the broken expression.
A negative SQLCODE means unsuccessful execution. Inserts did not land. A singleton SELECT did not fill hosts (unless you have a documented partial case). For -911 the whole unit of recovery was rolled back. For -913 the statement failed but the UR was not rolled back—you decide COMMIT or ROLLBACK. That difference is why the sign and the exact code both matter.
Shop talk often says “we got an 805” or “911.” Those are minus codes on z/OS. Writing +805 in a comment is wrong; +805 is not the DBRM-not-found error. The next pages call out real plus codes versus the famous minus codes that checklists sometimes label with a plus by habit.
After a statement, SQLCA.SQLCODE and GET DIAGNOSTICS CONDITION 1 DB2_RETURNED_SQLCODE tell the same story for the primary condition. Use GET DIAGNOSTICS when:
1234GET DIAGNOSTICS CONDITION 1 V_CODE = DB2_RETURNED_SQLCODE, V_STATE = RETURNED_SQLSTATE, V_TEXT = MESSAGE_TEXT;
Do not GET DIAGNOSTICS as a substitute for checking SQLCODE on the original statement—check first, then diagnose. GET DIAGNOSTICS itself can return a warning if a VARCHAR host truncates; that warning is in DB2_GET_DIAGNOSTICS_DIAGNOSTICS, not a wipe of the previous area.
Match the version (Db2 12 versus 13). Do not use LUW SQL0204N text for z/OS -204 without checking; numbers overlap, wording and system action can differ. Bookmark: https://www.ibm.com/docs/en/db2-for-zos/12.0.0?topic=codes-sql
When you open a code, read more than the title. Explanation is what happened. System action tells you whether the cursor closed, whether a rollback already ran, whether hosts were left unchanged. Programmer response is the first fix to try. SQLSTATE lets you write class-based handlers. Related information links reason codes and messages. Later tutorial pages follow that same shape for each code.
SQLCODE is the librarian’s score after you ask for a book. Zero means “here it is.” Plus one hundred means “that shelf is empty.” Other plus numbers mean “here it is, but the cover is a bit torn—still usable.” Minus numbers mean “I did not give you a book; stop pretending I did.” SQLSTATE is a color sticker so every IBM library uses the same colors. GET DIAGNOSTICS is asking the librarian to read the whole incident report, not just the score. The IBM Codes book is the dictionary of scores.
1. IBM’s four-way split of SQLCODE is:
2. SQLSTATE 02000 corresponds to:
3. Where do you look up an SQLCODE on z/OS?
4. GET DIAGNOSTICS helps with SQLCODE when:
5. Writing “SQLCODE 911” without a sign is dangerous because: