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

DB2 commits with Cursor


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
ap_mainframes

Active User


Joined: 29 Dec 2005
Posts: 181
Location: Canada

PostPosted: Tue May 12, 2009 2:35 am
Reply with quote

Hello,

In my program, I have got a cursor. I do some processing based on the record it receive from cursor.

I need to commit ( manually ) in my program. Can some one tell me what all things I need to do with the cursor ? Like, do I need to repositon the cursor etc ?

Thanks for all the help anyone can provide.
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1248
Location: Richfield, MN, USA

PostPosted: Tue May 12, 2009 2:52 am
Reply with quote

If you use the WITH HOLD option of your OPEN CURSOR, it will remain open across COMMITs, otherwise a COMMIT will close it.
Back to top
View user's profile Send private message
ap_mainframes

Active User


Joined: 29 Dec 2005
Posts: 181
Location: Canada

PostPosted: Tue May 12, 2009 7:53 am
Reply with quote

Thanks..Do I need to worry about repositioning of Cursor ?
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1248
Location: Richfield, MN, USA

PostPosted: Tue May 12, 2009 8:32 am
Reply with quote

Once the cursor is closed, you would need to open it again. Your logic would determine whether or not you need to position the cursor at the desired fetched row.
Back to top
View user's profile Send private message
ap_mainframes

Active User


Joined: 29 Dec 2005
Posts: 181
Location: Canada

PostPosted: Tue May 12, 2009 9:31 am
Reply with quote

ok..but I will use WITH HOLD option so that the cursors are open..then I think I dont have to worry about repositioning..Is my assumption correct ?
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1248
Location: Richfield, MN, USA

PostPosted: Tue May 12, 2009 9:35 am
Reply with quote

Yes.
Back to top
View user's profile Send private message
ap_mainframes

Active User


Joined: 29 Dec 2005
Posts: 181
Location: Canada

PostPosted: Tue May 12, 2009 9:41 am
Reply with quote

Thank you Terry for your help.
Just to summarize my conclusions

I'll use WITH HOLD option in my open cursor. With that the cursor will be open even when commiting in the program. Hence, I dont have to reposition the cursor.

Please correct me if I am incorrect any where...

Once again appreciate your help !
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1248
Location: Richfield, MN, USA

PostPosted: Tue May 12, 2009 9:44 am
Reply with quote

That's about it. For more detailed info see the link at the top of the screen called IBM Manuals.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19243
Location: Inside the Matrix

PostPosted: Tue May 12, 2009 10:23 am
Reply with quote

Hello,

And to build confidence, create a very small program that is fed specific values to force different "found sets" for different iterations using the cursor. The only reason for the program is to exercise the question cursor and commit.

Do some commits and some without and put displays in the code to track the results.

When you see it work as you understand, it is a great confidence builder icon_smile.gif

If there are any surprises, someone will be here.
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1248
Location: Richfield, MN, USA

PostPosted: Tue May 12, 2009 8:58 pm
Reply with quote

Nothing beats writing little test programs as Dick suggests to better understand how things work.
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 12, 2009 10:03 pm
Reply with quote

I believe there is a work-culture problem here.

Quote:
Nothing beats writing little test programs as Dick suggests to better understand how things work


I fully agree and do it often. But it seems as if most of the posters
not only can not or will not do this -- for what ever reason.
Back to top
View user's profile Send private message
ap_mainframes

Active User


Joined: 29 Dec 2005
Posts: 181
Location: Canada

PostPosted: Wed May 13, 2009 12:47 am
Reply with quote

Alright, it worked for me and the results are fine.

Thks all for all the help.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19243
Location: Inside the Matrix

PostPosted: Wed May 13, 2009 12:57 am
Reply with quote

You're welcome.

Good to hear it is working - thanks for letting us know icon_smile.gif

d
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 -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Inserting into table while open selec... DB2 1
No new posts Is SQLCODE -811 possible while fetchi... DB2 1
No new posts Restart logic by using cursor name in... DB2 1
No new posts Seeking Resolution for SQKCODE -991 o... DB2 2
No new posts Multiple rows within Cursor when Coun... DB2 14
Search our Forums:

Back to Top