In this post, you’ll learn about the error message -501 the cursor identified in a fetch or close statement is not open in the IBM DB2 database , the reason why it occurs along with the solution to fix it
IBM DB2 Error Message
-501 the cursor identified in a fetch or close statement is not open
Reason for the Error
The application program attempted to either:� 1.�� FETCH using a cursor, or� 2.�� CLOSE a cursor� at a time when the specified cursor was not open.
Solution
Check for a previous SQLCODE that may have closed� the cursor.� Commit and rollback operations close cursors.� SQL codes� -404, -652, -679, -901, -904, -909, -910, -911, and -913 will force the� cursor to close.� After the cursor is closed, any fetches or close cursor� statements will receive this SQLCODE -501.� If no previous SQLCODEs have been issued, correct the logic of the� application program to ensure that the cursor is open at the time the� FETCH or CLOSE statement is executed.