Informix Error -666
-666 Variable variable-name must be declared INTEGER or SMALLINT.
In a FOR statement, loop variables that contain ranges must be declared to be INT or SMALLINT.
Example of error:
DEFINE var CHAR(10); FOR var IN (e1, e2 TO e3, e4) -- error ... END FOR;
Correction: Because the FOR statement contains a range operator (the TO clause), var must be declared as INT or SMALLINT.
Oninit® Troubleshooting Guidance
Reasons / Common Causes
-666 fires when a FOR statement's range-based loop variable (used with the TO clause) is
declared as a type other than INTEGER/SMALLINT — per the official guidance, a ranged FOR
loop variable specifically requires one of these two numeric types.
- A loop variable declared
CHAR,DECIMAL, or another non-integer type, per the official guidance's example contrast withCHAR— used in aFOR var = start TO endrange loop. - A variable reused from elsewhere in the routine (declared for a different purpose, with a
non-integer type) repurposed as a
FORloop's range variable without redeclaring it.
Solutions / Resolution
- Declare the loop variable as
INTEGERorSMALLINT, per the official guidance, before using it in a rangedFORstatement. - If the loop needs to iterate over non-integer values, iterate over an integer index instead and derive the non-integer value inside the loop body from that index.
Examples
The disallowed declaration
DEFINE i CHAR(2);
FOR i = 1 TO 10
...
END FOR;
-- -666: i must be INTEGER or SMALLINT for a ranged FOR
Corrected
DEFINE i INTEGER;
FOR i = 1 TO 10
...
END FOR;
Diagnostic Checks
- Check the declared type of every
FOR ... TO ...range loop's variable, confirming it'sINTEGER/SMALLINT.
Related Errors / Related Topics
- -660 — "Loop variable variable-name cannot be modified." A related
FOR-loop restriction, about modifying the loop variable inside the loop rather than its declared type.
A ranged FOR loop's variable must be INTEGER/SMALLINT — redeclare it, or iterate over an
integer index and derive any other value from it inside the loop.