Page 1 of 1

Cursor opened, fetched only.

PostPosted: Sat Nov 08, 2008 9:17 pm
by ranga_subham
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.

Re: Cursor opened, fetched only.

PostPosted: Sat Nov 08, 2008 11:49 pm
by dick scherrer
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.















'