PL/I · DB2 SQLCODE

SQLCODE -502: Cursor Already Open

What does SQLCODE -502: Cursor Already Open mean in PL/I?

The PL/I program issued an OPEN for a cursor that's already open — typically because error handling didn't CLOSE the cursor on a prior failed path, or the same cursor is opened twice inside a loop without an intervening CLOSE.

SQLCODE -502: Cursor Already OpenDB2 for z/OS · PL/I (embedded SQL)

Condition

The PL/I program issued an OPEN for a cursor that's already open — typically because error handling didn't CLOSE the cursor on a prior failed path, or the same cursor is opened twice inside a loop without an intervening CLOSE.

Fix

Add a CLOSE before re-opening the cursor (guarded by a check that it's actually open, or wrapped in its own error handling), and review the control flow for a path that skips CLOSE after an error.

Related db2 sqlcode