The DB2 Codes volume lists hundreds of SQLCODEs. You will not memorize them all. What you can memorize is the structure of every official entry, how to pull tokens from the SQLCA, and how to turn a negative into a fix instead of a mystery. This page is the method that sits beside the grouped SQLCODE tutorials.
Whether you read IBM Docs or a MainframeMaster group page, a useful SQLCODE write-up always covers the same checklist. If a blog posts only “-803 means duplicate,” it is incomplete—you still need SQLSTATE, tokens, and system action.
| Section | Why it matters |
|---|---|
| Message text | Exact IBM wording with token placeholders |
| Explanation | When and why Db2 sets this code |
| System action | Did data change? Was the statement aborted? |
| Programmer response | What you should change or check next |
| SQLSTATE | Portable 5-character condition class |
| Tokens / related | Names, RIDs, reason codes, related concepts |
People write +000 next to +100 in tables; the host variable is still integer 0. Never invent a plus version of a famous minus code (+911 is not a thing on z/OS for deadlock rollback—that is -911).
IBM message text includes placeholders such as constraint-name, indexspace-name, rid-number, reason-code, auth-id, and object-type. At runtime those placeholders become concrete values in SQLERRM / DSNTIAR output. Two -803s with different index spaces are different problems.
123456789101101 ERROR-MESSAGE. 05 ERROR-LEN PIC S9(4) COMP VALUE +720. 05 ERROR-TEXT PIC X(72) OCCURS 10 TIMES. 01 ERROR-TEXT-LEN PIC S9(9) COMP VALUE +72. * CALL 'DSNTIAR' USING SQLCA ERROR-MESSAGE ERROR-TEXT-LEN PERFORM VARYING I FROM 1 BY 1 UNTIL I > 10 IF ERROR-TEXT (I) NOT = SPACES DISPLAY ERROR-TEXT (I) END-IF END-PERFORM.
1234GET DIAGNOSTICS CONDITION 1 :msg = MESSAGE_TEXT, :stat = RETURNED_SQLSTATE, :code = DB2_RETURNED_SQLCODE;
Use the same loop for every unfamiliar code:
123456789Ticket template --------------- SQLCODE: -530 SQLSTATE: 23503 Message: ... FOREIGN KEY FK_EMP_DEPT ... Program / Package / Collection: ... Statement: INSERT INTO EMP ... Parent table checked: DEPT (no row for DEPTNO='Z99') Next action: insert parent or correct FK value
One giant page for every SQLCODE is unreadable. Group by failure mode:
When you meet a code outside those groups, still apply this page’s checklist—do not guess from LUW forums.
SQLCODEs are not the only numbers on a dump. Console DSN* messages, utility DSNU messages, and completion codes X'04E' /X'04F' often surround a bad night. If SQLCODE is 0 but the job abended, you are no longer in SQLCODE land—move to the messages and abends references.
Every SQLCODE page is like a recipe card for a kitchen mistake. The title is the mistake name (-803). The message is the loud buzzer text. Explanation is “you burned the toast.” System action is “we threw the toast away.” Programmer response is “use a lower heat.” SQLSTATE is the shared sticker color so every kitchen in the chain recognizes “burned food.” Tokens are which toaster and which slice. Read the whole card—not just the name.
1. Every IBM SQLCODE topic in the Codes book typically includes:
2. SQLSTATE is useful because:
3. DSNTIAR is used to:
4. Tokens in SQLCODE message text are:
5. Positive vs negative SQLCODE: