INF: Branching Within Static Batch in Embedded SQL for COBOL

Last reviewed: November 7, 1997
Article ID: Q66751
The information in this article applies to:

  - Microsoft Embedded SQL version 4.2 for COBOL

One of the extra features available with Microsoft's Embedded SQL for COBOL that is not generally allowed in embedded SQL is the ability to branch and loop within a static SQL statement batch. The following code demonstrates this ability by inserting and deleting an author from the pubs..authors table five times:

    WORKING-STORAGE SECTION.
    EXEC SQL INCLUDE SQLCA END-EXEC
    PROCEDURE DIVISION.

    EXEC SQL
      declare @looper int
      select @looper = 1
      while @looper < 11
      begin
        if exists (select * from authors where au_lname = "Frog")
        begin
          delete
          from authors
          where au_lname = "Frog"
        end
      else
        begin
          insert into authors values("123-45-6789","Frog","Kermit",
          "206 555-1212","Sesame Street","Redmond","WA","98052",1)
        end
      select @looper = @looper + 1
      end
    END-EXEC
    if sqlcode not = 0
      perform sql-error
    end-if
    stop run.

    sql-error.
    display "SQL error SQLCODE=" sqlcode.


Additional query words:
Keywords : SSrvCobol SSrvProg kbprg
Version : 4.2
Platform : OS/2


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: November 7, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.