Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Program failing with SQLCODE -501

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Program failing with SQLCODE -501
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: 1278
Location: Belgium

PostPosted: Tue Nov 09, 2010 2:49 pm    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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: 1278
Location: Belgium

PostPosted: Tue Nov 09, 2010 3:44 pm    Post subject:
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    Post subject:
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    Post subject:
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: 2422
Location: Netherlands, Amstelveen

PostPosted: Wed Nov 10, 2010 8:13 pm    Post subject:
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    Post subject: cursor sqlcode 501 not able to track after display
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    Post subject:
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    Post subject:
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts IMS BMP program causes 878 system abend Artemk IMS DB/DC 7 Tue Nov 22, 2016 8:26 pm
No new posts A sample of exit program for exit XMN... lind sh CICS 2 Mon Oct 03, 2016 5:07 pm
No new posts Need points to tune IMS Checkpoint Pr... satish.ms10 IMS DB/DC 2 Fri Sep 30, 2016 4:12 pm
No new posts ISPF program to set SCRNAME prino TSO/ISPF 5 Fri Sep 30, 2016 2:18 pm
No new posts Need Rexx Program to Load in to DB2 T... Hareesh Verma CLIST & REXX 22 Tue Sep 20, 2016 2:59 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us