Re: help with tables



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.

......
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.

.



Relevant Pages

  • Re: Can I use ESQL/C datetime type to define non-host variables / parameters (oops)
    ... Do I need to put the parameters with esql/c datatypes between EXEC SQL BEGIN DECLARE SECTION; and EXEC SQL END DECLARE SECTION;. ... If you want to write datetime as the type name without a typedef, then you have to use the ESQL/C preprocessor to change the datetime into dtime_t for you. ...
    (comp.databases.informix)
  • Re: Opinions on approach, please...
    ... It means the first column in the result set. ... EXEC SQL DECLARE c1 CURSOR FOR s1 END-EXEC. ...
    (comp.lang.cobol)
  • Re: ESQLC problem
    ... preprocessor step before the esqlc step. ... exec sql begin declare section; ... I can't think of any simple way to deal with this, unless the header ...
    (comp.databases.ingres)
  • Re: help with tables
    ... department into table2-entry from table2 ... This does not appear to work, at least not using the DB2 pre-processor. ... EXEC SQL ... BEGIN DECLARE SECTION ...
    (comp.lang.cobol)
  • Re: [Info-Ingres] ESQLC problem
    ... #ifdef BIG_STRING ... exec sql begin declare section; ... I can't think of any simple way to deal with this, unless the header ...
    (comp.databases.ingres)