Informix Error -696
-696 Variable variable-name has undefined value.
An SPL variable was referenced or a row field was set before a value was assigned.
Example of error:
DEFINE my_row_var1 (last_name CHAR(20), id INTEGER); DEFINE i, j INT;
LET i = j + 1; -- error LET my_row_var1.id = new_id; -- error
While
LET my_row_var1 = ROW(NULL::CHAR(20), NULL::INTEGER)::person_rt; LET my_row_var1.id = new_id; -- success
Correction: Assign all variables and parameters valid values before you use them.
Row type variables are allowed in SPL routines. Such variables must be initialized before they are used. To initialize a row type variable, you must initialize the entire variable. Initializing each field will not substitute for initializing the entire variable, and in fact you cannot initialize the individual fields until after you have initialized the entire variable. The following example shows correct and incorrect initialization of row type variables in SPL.
-- Example showing that row type variables in SPL must have the entire -- variable initialized. It is not sufficient to initialize the fields -- without initializing the entire variable. CREATE DATABASE tango;
drop table table1; drop row type person_rt restrict; drop function create_person_rt; CREATE ROW TYPE person_rt (last_name CHAR(20), id INTEGER); CREATE FUNCTION create_person_rt(new_name CHAR(20), new_id INTEGER) RETURNING person_rt; DEFINE my_row_var1 person_rt; -- You cannot initialize the individual fields of the variable until you -- have initialized the entire variable. If the following statement were -- executed at this point, it would fail with error -696. -- LET my_row_var1.id = new_id; -- Initialize the entire variable. LET my_row_var1 = ROW(NULL::CHAR(20), NULL::INTEGER)::person_rt; -- Now set the individual fields. LET my_row_var1.id = new_id; LET my_row_var1.last_name = new_name; RETURN my_row_var1; END FUNCTION; -- Sample usage: CREATE TABLE table1 (person_column person_rt); INSERT INTO table1 (person_column) VALUES (create_person_rt('Uhuru', 128)); CLOSE DATABASE; You must initialize the entire variable because the engine can track whether or not the entire variable has been initialized but cannot track initialization on a field-by-field basis.
Oninit® Troubleshooting Guidance
Reasons / Common Causes
-696 fires when an SPL variable (or a row-type field) is referenced before it's ever been assigned a value — per the official guidance, this applies with a specific twist to row-type variables: the entire row variable must be initialized as a whole before any individual field of it can be set; initializing fields one at a time doesn't substitute for initializing the whole variable first, and in fact isn't even possible until the whole variable has been initialized.
- An ordinary scalar variable referenced before any
LETever assigned it a value — the direct, common cause for non-row variables. - A row-type variable's individual field set before the row variable itself was initialized as a whole, per the official guidance — the specific row-type twist: field-by-field initialization can't come first.
- A variable assigned inside a conditional branch that wasn't actually taken, leaving it still undefined when referenced afterward.
Solutions / Resolution
- Assign every variable and parameter a valid value before using it, per the official guidance.
- For a row-type variable, initialize the entire variable first, per the official
guidance, before setting any individual field:
DEFINE v_order ROW(order_id INT, status CHAR(10)); LET v_order = ROW(0, ''); LET v_order.status = 'pending'; - Trace every conditional path leading to the variable's use, confirming it's assigned on every path, not just the one that happened to be tested during development.
Examples
The disallowed field-first attempt
DEFINE v_order ROW(order_id INT, status CHAR(10));
LET v_order.status = 'pending';
-- -696: v_order itself was never initialized as a whole
Corrected — initialize the whole row first
DEFINE v_order ROW(order_id INT, status CHAR(10));
LET v_order = ROW(0, '');
LET v_order.status = 'pending';
Diagnostic Checks
- Trace the variable back to its first assignment, confirming an actual
LET(assigning the whole variable, for row types) precedes every use.
Related Errors / Related Topics
No closely related error codes are cross-referenced for -696 in this set yet.
For row-type variables specifically: initialize the whole variable with a single LET before
setting any individual field — field-by-field initialization can't come first.