QUICK ANSWER
A statement refers to a cursor that has not been declared or allocated, or that was deallocated or is out of scope.
LIKELY CAUSES, IN THE ORDER OF THIS ENTRY
- The cursor was not declared or allocated before it was referenced.
- A positioned UPDATE or DELETE was used on an allocated cursor, which is not supported.
- A CLOSE or ROLLBACK deallocated the allocated cursor.
- A COMMIT deallocated it because the stored procedure's cursor was not WITH HOLD.
- The stored procedure was called again and returned new result sets.
- The declaration is not in scope for the reference.
CHECKED 14 Nov 2026 IBM: Db2 13 - Codes - SQLCODE -504 | Db2 for z/OS 13.0.0
MOST LIKELY
The cursor was not declared or allocated before it was referenced.
FIRST CHECK
Check the program or SQL routine for a missing or misspelled DECLARE or ALLOCATE CURSOR, placed before use.
TRY IT ▸
Site search
What it means
The cursor name was used before a DECLARE CURSOR or ALLOCATE CURSOR was in effect for it, or the cursor is no longer valid.
The statement is not processed.
Typical causes
- The cursor was not declared or allocated before it was referenced.
- A positioned UPDATE or DELETE was used on an allocated cursor, which is not supported.
- A CLOSE or ROLLBACK deallocated the allocated cursor.
- A COMMIT deallocated it because the stored procedure's cursor was not WITH HOLD.
- The stored procedure was called again and returned new result sets.
- The declaration is not in scope for the reference.
How to fix it
- Check the program or SQL routine for a missing or misspelled DECLARE or ALLOCATE CURSOR, placed before use.
- Call the stored procedure again and reissue ASSOCIATE LOCATORS and ALLOCATE CURSOR after a COMMIT, ROLLBACK or CLOSE.
- Declare the procedure's cursor WITH HOLD so COMMIT does not deallocate it.
- If the cursor name shows as <UNKNOWN>, check precompile warnings on the DECLARE or ALLOCATE statement.
Suggest a tool or report a wrong answer · How it works and why it is safe
No mail app opens? Write to hello@mainframepath.com . Please do not send confidential code or data.