ID Number: Q66751
1.10 1.11 4.20
OS/2
Summary:
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 reference words: Embedded SQL for COBOL