← All errors

SQLCODE -502

SQL0502 Cursor already open

IBM message text
Cursor &1 already open or allocated.
SQLCODE
-502
SQLSTATE
24502

Most common cause

OPEN on a cursor that is still open. Typical when the program is called again in the same activation group without having closed the cursor the previous time.

Other causes

  • An error branch leaves the loop skipping the CLOSE.

How to fix it

Run a CLOSE before the OPEN (ignoring -501), or make sure every exit from the loop goes through the CLOSE.

Related errors

Text and codes from IBM documentation for 7.6. Checked on .