IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Program failing with SQLCODE -501


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
devd

New User


Joined: 19 Mar 2009
Posts: 11
Location: Chennai

PostPosted: Tue Nov 09, 2010 2:40 pm
Reply with quote

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
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Tue Nov 09, 2010 2:49 pm
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Nov 09, 2010 3:00 pm
Reply with quote

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
View user's profile Send private message
devd

New User


Joined: 19 Mar 2009
Posts: 11
Location: Chennai

PostPosted: Tue Nov 09, 2010 3:24 pm
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Nov 09, 2010 3:27 pm
Reply with quote

at this point, what kind of responses do you expect?
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Tue Nov 09, 2010 3:44 pm
Reply with quote

Put a display before your close statement.
It is quite possible that you pass there twice.
Back to top
View user's profile Send private message
VijayKrish

New User


Joined: 30 Jun 2010
Posts: 10
Location: India

PostPosted: Wed Nov 10, 2010 12:05 pm
Reply with quote

-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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Nov 10, 2010 2:21 pm
Reply with quote

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
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2481
Location: Netherlands, Amstelveen

PostPosted: Wed Nov 10, 2010 8:13 pm
Reply with quote

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
View user's profile Send private message
Ashish Paliwal

New User


Joined: 17 Mar 2011
Posts: 2
Location: India

PostPosted: Fri Apr 29, 2011 10:09 am
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Apr 29, 2011 2:25 pm
Reply with quote

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
View user's profile Send private message
Ashish Paliwal

New User


Joined: 17 Mar 2011
Posts: 2
Location: India

PostPosted: Tue May 03, 2011 11:03 am
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue May 03, 2011 11:33 am
Reply with quote

Ashish Paliwal,

thx for getting back to us with the resolution of your problem.
and congratulations for solving it.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Error to invoke MPP program through B... IMS DB/DC 3
No new posts SQLCODE=-311 in Cobol SP-DB2. COBOL Programming 2
No new posts Using API Gateway from CICS program CICS 0
No new posts DB2 Event passed to the Application P... DB2 1
No new posts How to pass the PARM value to my targ... COBOL Programming 8
Search our Forums:

Back to Top