The program tried to fetch from, or close, a cursor at a time when it was not open. The statement cannot be processed, and every later FETCH or CLOSE on that cursor gets -501 until it is opened again.
Typical causes
An earlier CLOSE statement closed the cursor.
A commit or rollback closed it.
An earlier error closed it, such as -679, -901, -904, -909, -910, -911, -913 or -952.
An error when updating an object (-404, -652), an arithmetic error in an aggregate function (-802), or an error during predicate processing.
How to fix it
Look for the earlier closing event in the job output and SQLCA history.
Correct the program logic so the cursor is open when FETCH or CLOSE runs.