Well, yes, but that was not the question. (I guess my question was a bit
ambiguous. Sorry.)
A 'multi-row' fetch (not sure if that is the correct name) appears to allow
you to declare a COBOL table in working storage, and do a single FETCH
statement to populate it with a multi-row result set.
Apparently this is supported in DB2 for z/OS, as in the example I gave. Not
having access to DB2 for z/OS myself I can't test it, but it is stated in
the manual, and a z/OS programmer is the one who I got the example from.
Personally, I'm fairly happy with using OPEN FETCH/FETCH/FETCH CLOSE, but
there's an argument on comp.lang.cobol that retrieving multiple rows with a
single FETCH is show how 'better' or 'more modern' or some such thing! :-)
Frank
n 1/31/2008 at 12:47 PM, in message <fn**********@new7.xnet.com>, Hemant
Shah<sh**@typhoon.xnet.comwrote:
You need to open the cursor before fetching.
In procedure division:
exec sql
open cursor-x
end-exec
perform until sqlcode not = zero
exec sql
fetch cursor-x
into :T2-NAME, :T2-DEPT
end-exec
* Do something with the data.
end-perform.
exec sql
close cursor-x
end-exec
While stranded on information super highway Frank Swarbrick wrote:
>Is there a way to do a multi-row fetch in to a COBOL table with DB2/LUW?
>Apparently the following is supported in z/OS, but not LUW (or at least
I
>couldn't get it to work):
WORKING-STORAGE SECTION.
EXEC SQL
INCLUDE SQLCA
END-EXEC
EXEC SQL
BEGIN DECLARE SECTION
END-EXEC
01 table2-area.
05 table2-entry.
10 t2-name pic x(30) occurs 100.
10 t2-dept pic x(04) occurs 100.
EXEC SQL
END DECLARE SECTION
END-EXEC
EXEC SQL
DECLARE CURSOR-X CURSOR FOR
select name, dept
from test.table2
where name in (select distinct name from test.table1)
END-EXEC.
......
PROCEDURE....
exec sql
FETCH NEXT CURSOR-X
into :T2-NAME, :T2-DEPT
for 100 rows
end-exec
Frank