MainframeKit

-303

SQLSTATE 42806NEGATIVE SQLCODE

A value could not be assigned to an output host variable because the data types are not compatible, for example a character column fetched into a numeric field.

MOST LIKELY

An INTO list in the wrong order, so a character column lands in a numeric variable.

FIRST CHECK

Use the position number to find the column and the variable.

TRY IT ▸

Record decoder

What it means

On a FETCH, SELECT INTO, VALUES INTO, CALL or SET, Db2 must assign a column value to one of your variables. If the two data types cannot be assigned to each other, the statement fails. The position number in the message tells you which variable.

Numbers go into numeric variables (and certain string types), character strings into character variables, graphic into graphic, binary into binary, and so on. A datetime value must go into a character variable of the right length.

Typical causes

  • An INTO list in the wrong order, so a character column lands in a numeric variable.
  • A host variable declared with a different type from the column.
  • A column whose data type changed but the program was not updated.
  • A date or timestamp fetched into a variable that is too short.

How to fix it

  1. Use the position number to find the column and the variable.
  2. Compare the column type in SYSIBM.SYSCOLUMNS with the host variable declaration.
  3. Fix the INTO list order or the declaration (DCLGEN helps keep them in step), then recompile and rebind.

Example

Illustrative only; names and values are invented.

EXEC SQL SELECT LASTNAME, SALARY INTO :WS-SALARY, :WS-NAME ...
SQLCODE = -303 (columns and host variables in the wrong order)