MainframeKit

-302

SQLSTATE 22001 or 22003NEGATIVE SQLCODE

An input host variable or parameter held a value that is invalid or too large for its target column, often bad packed-decimal data or a string that is too long.

MOST LIKELY

A COMP-3 host variable containing spaces, low-values or other non-numeric bytes.

FIRST CHECK

Use the position number in the message to find the host variable or parameter.

TRY IT ▸

Record decoder

What it means

Db2 checked a value coming from your program and found it could not fit the target. The position number in the message tells you which host variable (for INSERT, UPDATE, MERGE, DELETE, SELECT, VALUES INTO or SET) or which parameter (for CALL or a function) is at fault.

SQLSTATE 22003 means a number was too large for the target. SQLSTATE 22001 covers the other cases, such as a string that is too long or a decimal host variable that does not hold valid packed-decimal data.

Typical causes

  • A COMP-3 host variable containing spaces, low-values or other non-numeric bytes.
  • A string host variable longer than the column it is stored in.
  • A number larger than the column precision allows.
  • A copybook out of step with the table definition.
  • A host variable at the wrong position because the INTO or VALUES list is misaligned.

How to fix it

  1. Use the position number in the message to find the host variable or parameter.
  2. Display its contents in hex to check for invalid packed-decimal data.
  3. Compare its length and type with the column in SYSIBM.SYSCOLUMNS.
  4. Initialise numeric fields properly, regenerate declarations with DCLGEN if needed, and rerun.

Example

Illustrative only; names and values are invented.

SQLCODE = -302, SQLSTATE = 22001
-- input variable 3 (WS-DEPT-NAME, 40 bytes) is longer than DEPTNAME VARCHAR(36)