# SQLCODE -310: Decimal host variable holds non-decimal data

Source: https://wndsoftware.com/mainframe-errors/sqlcode-310

### SQLCODE -310: Decimal host variable holds non-decimal data

SQLCODE -310 (SQLSTATE 22023) means a decimal host variable or routine parameter contains data that isn't a valid packed decimal number. Db2 refuses to use it. The message gives the variable or parameter number.


#### Other names for this code

Also written as `SQL -310`, `SQLCODE=-310`, `SQLCODE = -310`, `db2 -310`, `sqlstate 22023`, `decimal host variable contains non-decimal data`, `db2 -310 packed decimal`.


### What it means

Db2 DECIMAL values are held as packed decimal, two digits per byte with a sign in the last half-byte. In COBOL that is a COMP-3 field. When a program passes a DECIMAL host variable to Db2, Db2 checks that the bytes really are packed decimal. If they aren't, it fails the statement instead of storing or comparing garbage. The code is usually -310, though IBM's -302 topic also lists invalid decimal data as one of its causes.

IBM gives two sources for the bad value. One is an application host variable, in an INSERT, UPDATE, MERGE, DELETE, SELECT, VALUES INTO, SET or FETCH statement. Then the number in the message is the host variable number. The other is a parameter passed to or from a user-defined function or stored procedure. Then the number is the parameter number.

This is the Db2 relative of the S0C7 abend. The cause is the same, a numeric field holding spaces, low-values or other bytes that aren't a valid number. The difference is that Db2 catches it and returns an SQLCODE, so the program doesn't abend.


### Common causes

- A COMP-3 host variable that was never initialized, so it still holds low-values or spaces when the INSERT or UPDATE runs.
- A record layout that doesn't match the input file, so a packed field is filled from the wrong bytes.
- A group MOVE or redefinition that copies character data over a packed field.
- A stored procedure or function parameter built with the wrong length or precision by the caller, so its bytes are read as the wrong number of digits.
- A bug in a tool or program that moves only part of a packed field. IBM has fixed several of these in its own tools.


### How to find the problem

- Read the number in the `DSNT408I` message. Count the host variables in the statement, or the parameters in the CALL or function, to find the field.
- Display that field in hex just before the statement runs. Valid packed decimal has a digit 0 to 9 in every half-byte except the last, which holds the sign, normally C, D or F.
- Check where the field was last set. Look for missing VALUE clauses or INITIALIZE statements, and for group moves over it.
- For a stored procedure, compare the caller's parameter declarations with the definition in SYSIBM.SYSPARMS.


### How to fix it

- Initialize every packed decimal host variable, with VALUE ZERO or INITIALIZE, before it can reach an SQL statement.
- Check input data before using it, for example with `IF WS-AMOUNT IS NUMERIC`, and reject or report bad records.
- Use the current DCLGEN and copybooks so the program's fields match the table and the file.
- Declare stored procedure and function parameters with the same precision and scale as the routine definition.
- If the bad data comes from an IBM or vendor tool, check for a fix from the supplier.


### What it looks like


```text
DSNT408I SQLCODE = -310, ERROR:  DECIMAL HOST VARIABLE OR PARAMETER 2 CONTAINS NON-DECIMAL DATA
DSNT418I SQLSTATE   = 22023 SQLSTATE RETURN CODE
```


### IBM documentation

[IBM documentation: -310](https://www.ibm.com/docs/en/db2-for-zos/13.0.0?topic=codes-310). Use the documentation for your installed release.

[Report a correction to WND Software](https://wndsoftware.com/contact#message).

Technical reviewer: [Albert Joseph](https://wndsoftware.com/authors/albert-joseph), WND Software.

Last reviewed 2026-10-18 by the WND Software team. Written in our own words. For the full reference, check IBM’s Db2 for z/OS documentation for your release.


### Related codes

[SQLCODE -302 Input value invalid or too large Read →](https://wndsoftware.com/mainframe-errors/sqlcode-302)
[SQLCODE -301 Input host variable type can't be used Read →](https://wndsoftware.com/mainframe-errors/sqlcode-301)
[SQLCODE -304 Value out of range for host variable Read →](https://wndsoftware.com/mainframe-errors/sqlcode-304)
[S0C7 Data exception Read →](https://wndsoftware.com/mainframe-errors/s0c7)
[SQLCODE -180 Invalid date, time or timestamp string Read →](https://wndsoftware.com/mainframe-errors/sqlcode-180)

### Questions


#### Is -310 the same problem as an S0C7 abend?

It's the same kind of bad data, a packed field that doesn't hold a valid number. S0C7 happens when the program does arithmetic on it. -310 happens when the program passes it to Db2.


#### How is -310 different from -302?

They overlap. IBM's -302 topic covers values that are too long or too large, and also a decimal host variable holding invalid decimal data, with SQLSTATE 22001. -310 is the code dedicated to non-decimal data in a decimal variable or routine parameter, with SQLSTATE 22023. Whichever one you get, display the packed fields in hex.


#### Is SQL0310N on Db2 for LUW the same error?

No. On Db2 for LUW, SQL0310N means a statement has too many host variables. Search results for -310 often mix the two, so check which platform a page is about.

[Db2 SQLCODEs](https://wndsoftware.com/mainframe-errors/db2-sqlcodes) · [SQLCODE -305](https://wndsoftware.com/mainframe-errors/sqlcode-305) · [SQLCODE -311](https://wndsoftware.com/mainframe-errors/sqlcode-311)

[← All error codes](https://wndsoftware.com/mainframe-errors/)
