|
View previous topic :: View next topic
|
| Author |
Message |
chandracdac
New User
Joined: 15 Jun 2007 Posts: 92 Location: bangalore
|
|
|
|
| hai pls explain me how to resolve the sqlcode -501. |
|
| Back to top |
|
 |
ousep143
New User
Joined: 06 Oct 2007 Posts: 32 Location: India
|
|
|
|
Hi Chandra,
Without opening a cursor, you have fetched or closed the cursor. Before fetch the data from DB2,you must open the cursor.
Regards
 |
|
| Back to top |
|
 |
kovur
New User

Joined: 15 Nov 2007 Posts: 36 Location: India
|
|
|
|
Explanation: The application program attempted to either:
FETCH using a cursor, or
CLOSE a cursor
at a time when the specified cursor was not open.
System Action: The statement cannot be executed.
Programmer Response: Check for a previous SQL return code that may have closed the cursor. Commit and rollback operations close cursors. SQLCODES -404, -652, -679, -802, -901, -904, -909, -910, -911, -913, and -952 may force the cursor to close. After the cursor is closed, any fetches or close cursor statements will receive this SQLCODE -501.
If no previous SQL return codes 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. |
|
| Back to top |
|
 |
ksk
Active User
.jpg)
Joined: 08 Jun 2006 Posts: 355 Location: New York
|
|
|
|
Hi,
Description of error is "-501 Cursor not open on FETCH". Description itself is self-explanatory. |
|
| Back to top |
|
 |
chandracdac
New User
Joined: 15 Jun 2007 Posts: 92 Location: bangalore
|
|
|
|
| Hai frends i know -501 is the cursor problem i just want to how to resolve that one, please explain me |
|
| Back to top |
|
 |
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
| chandracdac wrote: |
| Hai frends i know -501 is the cursor problem i just want to how to resolve that one, please explain me |
OPEN the cursor before you do a fetch! |
|
| Back to top |
|
 |
ksk
Active User
.jpg)
Joined: 08 Jun 2006 Posts: 355 Location: New York
|
|
|
|
Understanding SQLCODE -501 Error Message:
| Code: |
SQLCODE -501: "The cursor identified in a FETCH or CLOSE statement is not open."
Common Causes:
Cursor Not Opened: |
The application program attempted to fetch rows from a cursor that had not been opened yet. Cursor Closed Prematurely:
The cursor was closed before the FETCH or CLOSE statement was executed.
Logical Errors in Code:
There may be logical errors in the application code that caused the cursor not to be opened or to be closed prematurely.
Steps to Resolve SQLCODE -501:
Check OPEN Statement:
Ensure that the cursor is properly opened using the OPEN statement before any FETCH or CLOSE operations are performed.
Example:
| Code: |
EXEC SQL
OPEN cursor-name
END-EXEC. |
Sequence of Operations:
Verify the sequence of SQL operations in your application. Ensure that the OPEN statement is executed before any FETCH or CLOSE operations on the cursor.
Example Sequence:
DECLARE cursor
OPEN cursor
FETCH from cursor
CLOSE cursor
Debugging the Application:
Use debugging techniques to trace the execution flow of the application. Ensure that the OPEN statement for the cursor is reached before any FETCH or CLOSE statements are executed.
Insert debugging or logging statements to monitor the cursor's state.
Check Cursor Declaration:
Ensure that the cursor is correctly declared and that its scope allows it to be opened and accessed as needed.
Review Program Logic:
Carefully review the program logic to ensure that the cursor is not inadvertently closed before all fetch operations are completed.
Example:
| Code: |
PERFORM UNTIL SQLCODE <> 0
EXEC SQL
FETCH cursor-name INTO :host-variable
END-EXEC
IF SQLCODE = 0
* Process fetched row
END-IF
END-PERFORM
EXEC SQL
CLOSE cursor-name
END-EXEC. |
|
|
| Back to top |
|
 |
rag swain
New User

Joined: 17 Dec 2007 Posts: 33 Location: pune,INDIA
|
|
|
|
| Check the option of using WITH HOLD coz sometimes while you do a fetch and process data and afterwards explicitly do a COMMIT, the cursor is closed, the next time when you try to fetch, end up with -501 error. thats why it says do an OPEN on the cursor before FETCH. |
|
| Back to top |
|
 |
|
|