What it means
Input host string variables are described to Db2 by a length, which sits in the SQL descriptor area (SQLDA). When Db2 evaluates the statement it reads that length. A negative value, or one above the allowed maximum, cannot describe a real string, so Db2 stops the statement. The message gives the position of the variable in the SQLDA, which tells you which input is at fault.
The cause is usually in the program rather than in the table data. The length often comes from a computed field, a moved value or an uninitialised variable, so check how it is set before the statement runs.
Typical causes
- A length field calculated from other values that went below zero.
- A length moved from a field that was never initialised.
- A length above the allowed maximum, for example from a field sized wrongly.
- Dynamic SQL where the program builds the length values itself.
- A length stored at the wrong offset in a structure, so a different value is read.
How to fix it
- Note the position number in the message and find the matching host variable in the statement, counting from 1.
- Display that length value just before the statement runs.
- Initialise length fields and check the arithmetic that sets them.
- Correct the program so that no negative or oversized length is ever passed.
- Rerun the program after the correction.
Example
Illustrative only; names and values are invented.
SQLCODE = -311, input host variable number 3 has a negative length
-- WS-NAME-LEN computed as WS-END-POS - WS-START-POS gave -4