multirow fetch with embedded SQL

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Frank Swarbrick

    #1

    multirow fetch with embedded SQL

    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

  • Hemant Shah

    #2
    Re: multirow fetch with embedded SQL


    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
    >
    --
    Hemant Shah /"\ ASCII ribbon campaign
    E-mail: NoJunkMailshah@ xnet.com \ / ---------------------
    X against HTML mail
    TO REPLY, REMOVE NoJunkMail / \ and postings
    FROM MY E-MAIL ADDRESS.
    -----------------[DO NOT SEND UNSOLICITED BULK E-MAIL]------------------
    I haven't lost my mind, Above opinions are mine only.
    it's backed up on tape somewhere. Others can have their own.

    Comment

    • Frank Swarbrick

      #3
      Re: multirow fetch with embedded SQL

      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 <fnt8kr$hdu$1@n ew7.xnet.com>, Hemant
      Shah<shah@typho on.xnet.comwrot e:
      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
      >>

      Comment

      • Serge Rielau

        #4
        Re: multirow fetch with embedded SQL

        This support hasn't been added yet.
        The same is true for INSERT and MERGE.
        DB2 for zOS is leading the charge here.

        First time is see the requirement against DB2 for LUW.

        Cheers
        Serge
        --
        Serge Rielau
        DB2 Solutions Development
        IBM Toronto Lab

        Comment

        • Karl Hanson

          #5
          Re: multirow fetch with embedded SQL

          Serge Rielau wrote:
          This support hasn't been added yet.
          The same is true for INSERT and MERGE.
          DB2 for zOS is leading the charge here.
          >
          First time is see the requirement against DB2 for LUW.
          >
          DB2 for i5/OS has supported the multiple-row-fetch clause for a number
          of releases (aka "FOR n ROWS"):




          --
          Karl Hanson

          Comment

          • Frank Swarbrick

            #6
            Re: multirow fetch with embedded SQL

            >>On 1/31/2008 at 6:26 PM, in message
            <60fapnF1prqc2U 1@mid.individua l.net>,
            Serge Rielau<srielau@ ca.ibm.comwrote :
            This support hasn't been added yet.
            The same is true for INSERT and MERGE.
            DB2 for zOS is leading the charge here.
            >
            First time is see the requirement against DB2 for LUW.
            Do you mean that there *is* a requirement, or that I should submit one?

            Thanks,
            Frank

            Comment

            • Serge Rielau

              #7
              Re: multirow fetch with embedded SQL

              Frank Swarbrick wrote:
              >>>On 1/31/2008 at 6:26 PM, in message
              <60fapnF1prqc2U 1@mid.individua l.net>,
              Serge Rielau<srielau@ ca.ibm.comwrote :
              >This support hasn't been added yet.
              >The same is true for INSERT and MERGE.
              >DB2 for zOS is leading the charge here.
              >>
              >First time is see the requirement against DB2 for LUW.
              >
              Do you mean that there *is* a requirement, or that I should submit one?
              You should submit it. Obviously it exists (and was addressed) for DB2
              for i5/OS and zOS.

              Cheers
              Serge

              --
              Serge Rielau
              DB2 Solutions Development
              IBM Toronto Lab

              Comment

              • Frank Swarbrick

                #8
                Re: multirow fetch with embedded SQL

                >>On 2/1/2008 at 11:20 AM, in message
                <60h67uF1qqqmaU 1@mid.individua l.net>,
                Serge Rielau<srielau@ ca.ibm.comwrote :
                Frank Swarbrick wrote:
                >>>>On 1/31/2008 at 6:26 PM, in message
                ><60fapnF1prqc2 U1@mid.individu al.net>,
                >Serge Rielau<srielau@ ca.ibm.comwrote :
                >>This support hasn't been added yet.
                >>The same is true for INSERT and MERGE.
                >>DB2 for zOS is leading the charge here.
                >>>
                >>First time is see the requirement against DB2 for LUW.
                >>
                >Do you mean that there *is* a requirement, or that I should submit one?
                You should submit it. Obviously it exists (and was addressed) for DB2
                for i5/OS and zOS.
                Sounds good.
                Thanks,
                Frank

                Comment

                Working...