SQL in COBOL Programs [ COBOL/HP-UX Language Reference for the Series 700 and 800 ] MPE/iX 5.0 Documentation
COBOL/HP-UX Language Reference for the Series 700 and 800
SQL in COBOL Programs
This COBOL compiler can accept SQL statements embedded in COBOL programs
in the format:
EC SQL SQL-statement END-EXEC
The EXEC SQL statement can be broken over as many lines as necessary,
following the normal COBOL rules.
SQL-statement is parsed and processed by the compiler and then passed to
the Database Services module for further processing. The syntax allowed
for SQL-statement is dependent on the database system in use, and is
defined in the manuals supplied with your system. The compiler extends
this syntax by translating SQL-statement to a form that can be processed.
These extensions to the syntax are defined in the section The Exec SQL
Statement later in this chapter.
Example
The following is an example of a complete COBOL program with embedded SQL
commands:
working-storage section.
exec sql begin declare section end-exec
* Examples of host variables declared within a
* DECLARE section
01 filler.
03 cust-no pic 9(4) packed-decimal.
03 cust pic X(20).
exec sql end declare section end-exec
* Example of host variable not declared within a
* DECLARE section
01 house-no pic 9(4) comp.
exec sql include sqlca end-exec
procedure division.
exec sql declare cust cursor for
select custno, custname, hseno
from region where postdept = 'rg1'
end-exec
exec sql open cust end-exec
perform until sqlcode not = 0
exec sql
fetch cust into :cust-no, :cust, :house-no
end-exec
display "customer-no: " cust-no
" customer-name: " cust
" house-no: " house-no
end-perform
exec sql close cust end-exec
stop run.
MPE/iX 5.0 Documentation