MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Having a CLOSE CURSOR is not necessary !?

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
mf_user
Intermediate


Joined: 01 Jun 2003
Posts: 372
Topics: 105

PostPosted: Thu Nov 22, 2007 7:54 am    Post subject: Having a CLOSE CURSOR is not necessary !? Reply with quote

Hi,

During a discussion, somebody raised a doubt:

Is it advisable to have Declare, Open, Fetch of Curor only? They say it is not necessary to have Close cursor statement because the DB2 takes care of it internally whether it's a rollback or commit.

They justify that having CLOSE CURSOR is necessary only if you are acting multiple times on same cursor because it requires open and close of the same cursor again and again.

Can somebody explain the technical fators please?

Thanks.
_________________
MF
==
Any training that does not include the emotions, mind and body is incomplete; knowledge fades without feeling.
==
Back to top
View user's profile Send private message Send e-mail
CZerfas
Intermediate


Joined: 31 Jan 2003
Posts: 211
Topics: 8

PostPosted: Fri Nov 23, 2007 4:40 am    Post subject: Reply with quote

Hello MF,

yes, the described mechanism is correct, you don't need a CLOSE CURSOR.

Nevertheless it is good programming practice to have a CLOSE in your code. It eases maintenance, if the same cursor has to be opened with different parameters again, for instance.

It is advisable, as well, to code the "unnecessary" COMMIT into your programm, so that your coding is complete and nothing is done "automatically" by the system. Those things could change over time.

just my two cents
Christian
Back to top
View user's profile Send private message
mf_user
Intermediate


Joined: 01 Jun 2003
Posts: 372
Topics: 105

PostPosted: Fri Nov 23, 2007 7:06 am    Post subject: Reply with quote

CZerfas, Thank you.

I wrote a small DB2-COBOL program without CLOSE CURSOR and it was closed automatically.

Actually, I have never seen an explicit COMMIT in any of our programs.
_________________
MF
==
Any training that does not include the emotions, mind and body is incomplete; knowledge fades without feeling.
==
Back to top
View user's profile Send private message Send e-mail
videlord
Beginner


Joined: 09 Dec 2004
Posts: 147
Topics: 19

PostPosted: Fri Nov 23, 2007 3:10 pm    Post subject: Reply with quote

most of time it's ok, even you allocate some memory without freeing in your code, system can handle it.

But i will say it's not a good code. It may depend on the compiler, the operation system. Some time it may cause problem.

Keep a good habit, make your code clear, clean.
Back to top
View user's profile Send private message
mf_user
Intermediate


Joined: 01 Jun 2003
Posts: 372
Topics: 105

PostPosted: Mon Nov 26, 2007 5:42 am    Post subject: Reply with quote

Ok. Thank you videlord.
_________________
MF
==
Any training that does not include the emotions, mind and body is incomplete; knowledge fades without feeling.
==
Back to top
View user's profile Send private message Send e-mail
dr_te_z
Beginner


Joined: 08 Feb 2007
Posts: 18
Topics: 3

PostPosted: Tue Nov 27, 2007 7:08 am    Post subject: Reply with quote

mf_user wrote:
I wrote a small DB2-COBOL program without CLOSE CURSOR and it was closed automatically.
Yeah? Did your program have an iteration where you open/fetch/close more than once?

In the old days (using adabas/ADASQL) I once encountered a program error where the "close" was not coded. The "open" following that did not select any rows and did not throw an abnormal SQLCODE. the next "open", however, did select the required data.
So the typical pattern: OK, not found, OK, not found, OK, not found... indicates a missing "close cursor".

I agree with CZerfas and advice to code the "close" always. This cursor technique is used in a lot of databases and some can handle a missing "close", others cannot.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group