Previous Topic: Delimited, Continued, and Commented StatementsNext Topic: Defining Host Variables


Placing an SQL Statement

Where You Can Put Statements

These are the rules for placing an SQL statement in a COBOL program:

Versions Prior to VS COBOL II

If your program is written for a version of COBOL that is prior to VS COBOL II, observe these guidelines:

COBOL Version Examples

This example is valid in VS COBOL II and later versions:

IF I < 100
  EXEC SQL
    SELECT EMP_LNAME,
           DEPT_ID
      INTO :EMP-LNAME,
           :DEPT-ID
      WHERE EMP_ID = :WK-EMP-ID
  END-EXEC.
  COMPUTE A = A + 1.

For a version of COBOL prior to VS COBOL II, the procedure above can be written:

IF I < 100
  PERFORM  PARAGRAPH-B THRU PARAGRAPH-B-END
  COMPUTE A = A + 1.

PARAGRAPH-B.
  EXEC SQL
    SELECT EMP_LNAME,
           DEPT_ID
      INTO :EMP-LNAME,
           :DEPT-ID
      WHERE EMP_ID = :WK-EMP-ID
  END-EXEC.
PARAGRAPH-B-END.