View previous topic :: View next topic
|
Author |
Message |
devd
New User
Joined: 19 Mar 2009 Posts: 11 Location: Chennai
|
|
|
|
I am facing with -501 sqlcode. It looks like my program was trying to close the cursor, so there was probably not any impact to the actual data being processed, assuming the cursor was being closed because of EOF.
Do we have any other option other than using WITH HOLD with cursor? I want to try something other than WITH HOLD as the cursor is getting closed due to EOF.
Thanks in advance
Regards,
D.Dash |
|
Back to top |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
your premises is wrong : A cursor does not get closed because sqlcode +100.
So your solution is wrong : there is no need to specify with hold for this reason.
A cursor can get closed because of explicit COMMIT or another serious sqlcode you're not trapping. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
you have done a good job of ignoring the facts.
did you actually open the cursor?
Quote: |
as the cursor is getting closed due to EOF. |
this is not true.
EOF is not a DB2 concept.
cursors are closed by a ROLLBACK or COMMIT when not OPENed WITH HOLD.
you need to review fundamental db2 concepts with regard to cursor.
your questions indicate very little understanding of db2.
you received a -501 because you attempted to FETCH or CLOSE a cursor that was not OPEN - simple as that.
either you did not OPEN the cursor
or
you CLOSEd it prior to the second CLOSE
(if indeed you received the -501 on a CLOSE sql invokation.
at this point I doubt your ability to maintain good logic control of your prg)
or
you issued a ROLLBACK or COMMIT (or one was issued for you e.g. -913)
you need to provide more specifics about your program in order to receive any help. |
|
Back to top |
|
|
devd
New User
Joined: 19 Mar 2009 Posts: 11 Location: Chennai
|
|
|
|
Quote: |
A cursor can get closed because of explicit COMMIT or another serious sqlcode you're not trapping.
|
There is not explicit COMMIT in the code
Quote: |
did you actually open the cursor?
|
Yes it is OPEN
In my case cursor is closed prior to second CLOSE. So I assumed it got closed when it reached EOF. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
at this point, what kind of responses do you expect? |
|
Back to top |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
Put a display before your close statement.
It is quite possible that you pass there twice. |
|
Back to top |
|
|
VijayKrish
New User
Joined: 30 Jun 2010 Posts: 10 Location: India
|
|
|
|
-501 THE CURSOR IDENTIFIED IN A FETCH OR CLOSE STATEMENT IS NOT OPEN
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.
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
posting what we all knew does not help.
what you need to do is:
Vijay Krishna wrote: |
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.
|
so again, what do you expect from us? |
|
Back to top |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
Quote: |
so again, what do you expect from us?
|
Be easy Dick, after all the TS is only a :
Occupation: Software Professional
Mainframe Skills: JCL,COBOL,DB2
I guess its something to test us. |
|
Back to top |
|
|
Ashish Paliwal
New User
Joined: 17 Mar 2011 Posts: 2 Location: India
|
|
|
|
hello,
i am getting the SQLCODE 501 although program is not going to COMMIT or ROLLBACK in program. logic in fetch is just to read the fetched row and move to different variable.it is not calling any para.
i have kept display befor and after the close statement
before sqlcode 100 (which is actually the cursor fetch)
after sqlcode 501
shall i use the WITH HOLD option, iam using the cursor just to fetch.
please guide me. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
instead of tagging on to an old thread,
that discussed to eternity the causes and solutions,
read the thread.
if you are getting a -501 on a Fetch,
either:- you have not OPENed the Cursor
- something CLOSEd the Cursor and you did not have appropriate logic to handle the situation
nothing magic about cursors.
nothing more to say,
other than
send me your program with €1000 and I will debug it for you. |
|
Back to top |
|
|
Ashish Paliwal
New User
Joined: 17 Mar 2011 Posts: 2 Location: India
|
|
|
|
ok dick thanks for te help, but we didnot properly looked into the cursor name and it was some other name.
sorrry for inconvinience and thanks a lot for the helpful answer. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Ashish Paliwal,
thx for getting back to us with the resolution of your problem.
and congratulations for solving it. |
|
Back to top |
|
|
|