Mainframe Path Start learning free
CoreError and abend codes-180

SQLCODE -180 / -181 — invalid date, time or timestamp

A date, time or timestamp was in the wrong format (-180) or out of range (-181). Usually spaces, low-values or a badly built date string.

What happened

An insert, update or query with date logic fails for some records but not others. The message names the data type that was rejected.

Program output via DSNTIAR (illustrative)
DSNT408I SQLCODE = -180, ERROR:  THE DATE, TIME, OR TIMESTAMP VALUE
         2026/13/01 IS INVALID
DSNT418I SQLSTATE   = 22007 SQLSTATE RETURN CODE

What it means

Db2 stores dates as real date values. When it receives a string it must convert it. -180 (SQLSTATE 22007) means the string's syntax is wrong: wrong separators, wrong length, letters, spaces. -181 (SQLSTATE 22008) means the syntax is fine but the value is impossible, such as month 13 or 30 February.

SQLERRMC usually carries the data type or the rejected value. It does not name the column, so the program must log the statement and key.

Typical causes

Symptoms

Fails only for certain records. Often the bad values come from one source system. It differs from a COBOL S0C7 because Db2 catches it and returns an SQLCODE instead of an abend.

Where to look

How to diagnose

  1. Note -180 or -181 and the rejected value or data type.
  2. Identify the statement and record key from the program log.
  3. Look at the raw input value in hex.
  4. Compare the format with what your site accepts; ISO YYYY-MM-DD is the safe choice.
  5. For -181, check the value is a real calendar date or time.

How to fix

Fix the bad source data with the data owner, or correct how the program builds the string. For optional dates, use a null indicator to store NULL instead of a fake date, if the column allows it. Then rerun or restart. To turn the raw SQLCA into readable text, call DSNTIAR (DSNTIAC in CICS) with the SQLCA and a message buffer, or use GET DIAGNOSTICS to fetch MESSAGE_TEXT, RETURNED_SQLSTATE and DB2_RETURNED_SQLCODE. Either way, write the full message to the job log before the program ends.

How to prevent

Production considerations

Interview question

What is the difference between SQLCODE -180 and -181?

Stuck on something else?
Ask the community or search the full course.

Ask a question