Cursor opened, fetched only.



IBM's flagship relational database management system

Cursor opened, fetched only.

Postby ranga_subham » Sat Nov 08, 2008 9:17 pm

Hi,

One of our production COBOL/DB2 program has coding like this:

 INITIALIZATION.
.
.
.
     PERFORM S0100-SYSIN-PROCESS.
     PERFORM S200-OPEN-FIRST-CURSOR.
     PERFORM S201-FETCH-FIRST-CURSOR.

 MAINLINE.                               
                                         
     PERFORM S100-DATA-PROCESS       
        UNTIL S-NO-MORE-ROWS             
     PERFORM S201-CLOSE-FIRST-CURSOR.
.
.
.
 S100-DATA-PROCESS.               
                                     
     PERFORM S210-UPDATE-ORDER.
     PERFORM S201-FETCH-FIRST-CURSOR.


The code in the INITIALIZATION para opens the cusor then does a FETCH. The INITIALIZATION is followed by MAINLINE para where S100- & S201- paras are executed. In S100-, we have another UPDATE followed by FETCH. I am not able to understand how this can be possible to open, fetch, update and fetch can run successfully !? I understand the cursor concept like after declare there should be a OPEN, FETCH and CLOSE but here the cursor is OPENed, FETCHed and goes to UPDATE para and again FETCH. Would somebody please explain me because of this any records are skipped or it is ok?

Thanks a lot.

Bye.
ranga_subham
 
Posts: 279
Joined: Fri Jul 18, 2008 7:46 pm
Has thanked: 0 time
Been thanked: 1 time

Re: Cursor opened, fetched only.

Postby dick scherrer » Sat Nov 08, 2008 11:49 pm

Hello,

That is how fetch is designed to work.

I understand the cursor concept
Your understanding is incomplete. Cursors are used when the "found set" may contain more than one row. Issuing fetch repeatedly is how the multiple rows are "read" into the program.















'
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times


Return to DB2

 


  • Related topics
    Replies
    Views
    Last post