RPG (IBM i / AS/400) · DB2 SQLCODE

SQLCODE -501 - Cursor Not Open

What does SQLCODE -501 - Cursor Not Open mean in RPG (IBM i / AS/400)?

The program issued a FETCH or CLOSE against a cursor that was never opened, usually because an earlier OPEN failed without the failure being checked, or the cursor was already closed by a prior CLOSE.

SQLCODE -501 - Cursor Not OpenDB2 for i · SQLRPGLE

Condition

The program issued a FETCH or CLOSE against a cursor that was never opened, usually because an earlier OPEN failed without the failure being checked, or the cursor was already closed by a prior CLOSE.

Fix

Check SQLCODE right after every OPEN before looping on FETCH, and guard retry logic so a re-entered subroutine doesn't try to FETCH or CLOSE a cursor that isn't currently open.

Related db2 sqlcode