Previous Topic: Embedding SQL StatementsNext Topic: Placing an SQL Statement


Delimited, Continued, and Commented Statements

Using SQL Statement Delimiters

When you embed an SQL statement in a COBOL application program, you must use these statement delimiters:

Note: The period following END-EXEC is optional. Include it wherever you would normally terminate a COBOL statement with a period.

The following example shows the use of SQL statement delimiters:

EXEC SQL
  INSERT INTO DIVISION VALUES ('D07','LEGAL',1234)
END-EXEC.

The statement text can be on the same line as the delimiters.

Continuing Statements

You can write SQL statements on one or more lines. No special character is required to show that a statement continues on the next line if you split the statement before or after any keyword, value, or delimiter.

You can use the COBOL continuation character, a hyphen (-), in column 7 when a string constant in an embedded SQL statement is split at column 72 and continued on the next line:

----+----1----+----2----+----3----+----4----+----5----+----6----+----7—
       EXEC SQL
         INSERT INTO SKILL
           VALUES (5678,'TELEMARKETING','PRESENT SALES SCRIPT OVER THE
      -'TELEPHONE, INPUT RESULTS')
       END-EXEC.

Inserting SQL Comments

To include comments within SQL statements embedded in a COBOL program, you can:

A comment that begins with the SQL comment characters (--) terminates at the end of the line (column 72).

You cannot use SQL comment characters to insert a comment in the middle of a string constant or delimited identifier.

The following example shows both methods of inserting comments within an embedded SQL statement:

----+----1----+----2----+----3----+----4----+----5----+----6----+----7—
       EXEC SQL
      *********  PERFORM UPDATE ON ACTIVE EMPLOYEES ONLY
         UPDATE BENEFITS
           SET VAC_ACCRUED = VAC_ACCRUED + 10,  -- Add 10 hours vacation
               SICK_ACCRUED = SICK_ACCRUED + 1  -- Add 1 sick day
           WHERE EMP_ID IN
             (SELECT EMP_ID FROM EMPLOYEE
             WHERE STATUS = 'A')
 END-EXEC.