Informix Error -4371: Cursors must be uniquely declared within one program module.
Cause and resolution
Cursors must be uniquely declared within one program module.
In the statement DECLARE cname CURSOR, the identifier cname can be used in only one DECLARE statement in the source file. This is true even when the DECLARE statement appears inside a function. Although a program variable made with the DEFINE statement is local to the function, a cursor within a function is still global to the whole module.
Oninit® Troubleshooting Guidance
Reasons / Common Causes
-4371 fires when the same cursor name is used in more than one DECLARE cname CURSOR
statement within one source file — per the official guidance, this holds even when the
DECLARE appears inside a function: unlike a DEFINEd program variable (which is local to
its function), a cursor is global to the whole module.
- The same cursor name declared in more than one
DECLARE ... CURSORstatement in the module, per the official guidance — the direct, only cause; cursor names aren't scoped per-function the way variables are.
Solutions / Resolution
- Rename one of the two cursors so each name is used in only one
DECLAREstatement within the module.
Examples
Two functions declaring the same cursor name
FUNCTION listOrders()
DECLARE cur CURSOR FOR SELECT * FROM orders;
END FUNCTION
FUNCTION listCustomers()
DECLARE cur CURSOR FOR SELECT * FROM customer;
-- -4371: "cur" is already declared above, even though these are
-- different functions
END FUNCTION
Corrected
FUNCTION listCustomers()
DECLARE cust_cur CURSOR FOR SELECT * FROM customer;
END FUNCTION
Diagnostic Checks
- Check every
DECLARE ... CURSORstatement across the whole module, including inside different functions, and rename any cursor name used more than once.
Related Errors / Related Topics
- -4372 — "The cursor cursor-name has not yet been declared in this program module. It must be declared before it can be used." A related cursor-declaration error, about a missing declaration rather than a duplicate one.
The same cursor name is declared more than once in the module (cursors are module-global, not function-local) — rename one of them.