Embed SQL statements in COBOL applications that use SQL

SQL statements can be coded in COBOL program sections as in this table.

SQL Statement Program Section

BEGIN DECLARE SECTION

END DECLARE SECTION

DECLARE VARIABLE

DECLARE STATEMENT

WORKING-STORAGE SECTION or LINKAGE SECTION

INCLUDE SQLCA

INCLUDE SQLDA

WORKING-STORAGE SECTION or LINKAGE SECTION
INCLUDE member-name DATA DIVISION or PROCEDURE DIVISION
Other PROCEDURE DIVISION

Each SQL statement in a COBOL program must begin with EXEC SQL and end with END-EXEC. If the SQL statement appears between two COBOL statements, the period is optional and might not be appropriate. The EXEC SQL keywords must appear all on one line, but the remainder of the statement can appear on the next and subsequent lines.

Example

An UPDATE statement coded in a COBOL program might be coded as follows:

         EXEC SQL
           UPDATE DEPARTMENT
           SET MGRNO = :MGR-NUM
           WHERE DEPTNO = :INT-DEPT
         END-EXEC.