Re: help with tables
- From: "Frank Swarbrick" <Frank.Swarbrick@xxxxxxxxxxxxxx>
- Date: Thu, 31 Jan 2008 11:42:31 -0700
<med2q3hfb6vi8gbtvf436o07sr4k1jg0n5@xxxxxxx>, Robert<no@xxxxxx> wrote:On 1/30/2008 at 8:25 PM, in message
On Wed, 30 Jan 2008 21:55:18 +0000, Frederico Fonseca
<real-email-in-msg-spam@xxxxxxxxx>
wrote:
The following is allowed on V9, but on Z/OS.
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.
Was that necessary? DB2, like Oracle, expands a Cobol group name into a
list of host
variables by using the next lower level, which should be elementary. In
other words:
05 table2-entry occurs 100.
10 t2-name pic x(30).
10 t2-dept pic x(04).
into :table2-entry
is expanded to
into :t2-name, :t2-dept
I don't know whether DB2 is smart enough to treat :t2-name as an array.
Oracle is.
If not, would :table2-entry.t2-name work?
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.
A cursor need not be declared in the data division, only before the
first reference to it.
I prefer to put the declaration just above the fetch, with the open and
close further
down.
I prefer cursors to be in the data division, because they are declarations
and not 'action' statements. By putting them in the procedure division one
who doesn't know any better (say, me a year ago) could think that the
declaration is actually doing something.
Now I could conceivable see it immediately *above* the paragraph.
Funny thing is that in VSE you *have* to put it in the procedure division.
So I've taken to putting all of my DECLARE CURSOR statements immediately
following the PROCEDURE DIVISION line. Bugs me, but hey...
Not that I don't see your point, that it could be nice to have the cursor
declaration near the FETCH. I'm just concerned about the confusion it may
cause to less knowledgeable programmers.
......
PROCEDURE....
exec sql
FETCH NEXT CURSOR-X
into :T2-NAME, :T2-DEPT
for 100 rows
end-exec
It seems that Windows/Unix versions do not allow multiple fetch/insert
rows. Pitty.
Hard to believe. I think the non-singleton select caused the error.
You're welcome to try it yourself, or at least provide an example that you
think would work and I could try it.
Frank
.
- References:
- Re: help with tables
- From: Frank Swarbrick
- Re: help with tables
- From: Frederico Fonseca
- Re: help with tables
- From: Robert
- Re: help with tables
- Prev by Date: Re: db2 prep and nested exec sql
- Next by Date: Re: help with tables
- Previous by thread: Re: help with tables
- Next by thread: Re: help with tables
- Index(es):
Relevant Pages
|