Learn it on Mainframe Path. Do it with Mainframe KIT.Learn on Mainframe Path ▸
Mainframe KIT ● Nothing leaves this tab

-501

SQLSTATE 24501NEGATIVE SQLCODE · CHECKED 2026-11-14
Checked against IBM documentation

A FETCH or CLOSE named a cursor that is not open.

QUICK ANSWER

A FETCH or CLOSE named a cursor that is not open.

LIKELY CAUSES, IN THE ORDER OF THIS ENTRY

  1. An earlier CLOSE statement closed the cursor.
  2. A commit or rollback closed it.
  3. An earlier error closed it, such as -679, -901, -904, -909, -910, -911, -913 or -952.
  4. An error when updating an object (-404, -652), an arithmetic error in an aggregate function (-802), or an error during predicate processing.

CHECKED 14 Nov 2026 IBM: -501 (Db2 13 for z/OS)

MOST LIKELY

An earlier CLOSE statement closed the cursor.

FIRST CHECK

Look for the earlier closing event in the job output and SQLCA history.

TRY IT ▸

Site search

What it means

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

  1. Look for the earlier closing event in the job output and SQLCA history.
  2. Correct the program logic so the cursor is open when FETCH or CLOSE runs.