General Rules in COBOL
SQL Statement Delimiters
SQL statements are delimited by the prefix EXEC SQL and the terminator END-EXEC. The prefix may be written in upper or lower case letters. In CONNX Embedded SQL mode, upper or lower case is permitted, and the prefix can be split over numerous lines, separated by any whitespace character. In ANSI mode, upper case is required and only whitespaces can separate the prefix keywords.
The terminator END-EXEC can be followed by an optional period (.). In order to be recognized, it has to be coded on the same line.
SQL Statement Placement
All SQL statements (with the exception of the BEGIN/END DECLARE and INCLUDE) can be specified wherever a COBOL statement can be specified within the Procedure Division of the embedded SQL COBOL program. Included COBOL source code must not contain any SQL statements, or any host variable declaration that will be used in SQL statements.
The SQL INCLUDE , BEGIN/END DECLARE statements must be specified in the WORKING STORAGE SECTION of the COBOL program.
Comments
SQL statements can contain COBOL comments that are marked with an asterisk in column 7, or SQL comments preceded by two minus characters.
COBOL example:
000015 EXEC SQL WHENEVER SQLERROR
000016* CONTINUE
000017 GOTO HANDLE-ERROR
000018 END-EXEC.
SQL example:
000015 EXEC SQL WHENEVER SQLERROR
000016 -- CONTINUE
000017 GOTO HANDLE-ERROR
000018 END-EXEC.