RPG (IBM i / AS/400) · DB2 SQLCODE
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.
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.
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.