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

DB2 cursor


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

New User


Joined: 16 Mar 2008
Posts: 90
Location: tamil nadu

PostPosted: Fri Jan 08, 2010 5:17 pm
Reply with quote

Hi,

We declare cursor in Cobol -db2 program . we open fetch and close the cursor

At which process the data is fetched from the table .

for ex: select a,b from Table t where c >10

Whether the value is fetched from table T while declaring or while opening or while fetching it .
Please help

Thanks,
L.nethaji
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Fri Jan 08, 2010 5:55 pm
Reply with quote

if you look at the pre-compiler listing, you will notice that a declare:
  • sets up the variables used by db2
  • inserts cobol code between your PROCEDURE DIVISION USING statement and the first line of your code which establishes addressability with db2 and your program. This code (unless you internally modify the 'flag') is only executed once - at the start of execution of your program - unless you issue a cancel for your program from a CALLing module.


FETCH is a db2 term used to define the process of populating your host variables (defined in the DECLARE CURSOR) with values obtained from the result table, which is built as a result of the OPEN Cursor sql statement. The result table contains values from rows/colums selected from Table T during the OPEN processing.

The Applications programming and SQL guide, as well as the DB2 for z/OS Application Programming Topics outline this and other topics.
Back to top
View user's profile Send private message
sushanth bobby

Senior Member


Joined: 29 Jul 2008
Posts: 1020
Location: India

PostPosted: Fri Jan 08, 2010 6:00 pm
Reply with quote

Nethaji,

Quote:
The rows of the result table can be derived during the execution of the OPEN statement and a temporary copy of a result table can be created to hold those rows. They can be derived during the execution of later FETCH statements. In either case, the cursor is placed in the open state and positioned before the first row of its result table. If the table is empty, the position of the cursor is effectively “after the last row.” The DB2 system does not indicate an empty table when the OPEN statement is
executed.


I got the above information from DB2 SQL reference --> Chapter 5. OPEN statement.

Thank You,
Sushanth
Back to top
View user's profile Send private message
Keanehelp

New User


Joined: 27 May 2008
Posts: 71
Location: USA, CA.

PostPosted: Sat Jan 09, 2010 2:23 am
Reply with quote

Fetch will fetch the data into the variables
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 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
No new posts Dynamic cursor name in Cobol program COBOL Programming 1
Search our Forums:

Back to Top