Coding SQL statements
Delimit SQL statements with EXEC SQL
and END-EXEC
. The EXEC SQL
and END-EXEC
delimiters
must each be complete on one line. You cannot continue them across
multiple lines. Do not code COBOL statements within EXEC SQL
statements.
About this task
You must have an
EXEC SQL CONNECT
statement so that when your
program runs it establishes a connection to the database. Below is an
example:EXEC SQL CONNECT TO dbname END-EXEC
You also need to do these special steps:
-
Code an
EXEC SQL INCLUDE
statement to include an SQL communication area (SQLCA) in theWORKING-STORAGE SECTION
orLOCAL-STORAGE SECTION
of the outermost program.LOCAL-STORAGE
is recommended for recursive programs. - Define all host variables that you use in SQL statements in the
WORKING-STORAGE SECTION
,LOCAL-STORAGE SECTION
, orLINKAGE SECTION
. However, you do not need to identify them withEXEC SQL BEGIN DECLARE SECTION
andEXEC SQL END DECLARE SECTION
.
You can use SQL statements even for large objects (such as BLOB and CLOB) and compound SQL.