SQLCODE -501
SQL0501 Cursor not open
- IBM message text
- Cursor &1 not open.
- SQLCODE
- -501
- SQLSTATE
- 24501
Most common cause
FETCH or CLOSE on a cursor that is not open, often because the OPEN failed and SQLCODE was not checked.
Other causes
- The cursor was closed by a COMMIT or ROLLBACK (no WITH HOLD).
- The cursor was opened in another call of the module, and CLOSQLCSR(*ENDMOD) closes it on exit.
How to fix it
Check SQLCODE after every OPEN. If you COMMIT inside the loop, declare the cursor WITH HOLD.
Related errors
Text and codes from IBM documentation for 7.6. Checked on .