Previous Topic: Host-Variable Definitions in COBOLNext Topic: INCLUDE Directive in COBOL


PROCEDURE DIVISION

The PROCEDURE DIVISION statement must be coded on the same line with no continuation.

The following sections discuss the requirements for embedding SQL in the PROCEDURE DIVISION of your program.

Declaring Cursors in COBOL

Cursors must be declared in the source:

Cursor declarations can be made in the:

The recommended practice is to place all cursor definitions immediately before the PROCEDURE DIVISION statement.

Cursor definitions are declarations, not action (procedural) statements.

Declaring Exceptions in COBOL

An exception declaration specifies a COBOL action to be taken when an exception occurs during execution of an SQL statement. The form of the exception declaration is:

EXEC SQL
     WHENEVER condition exception-action
END-EXEC

Following are the exception conditions for ANSI mode and extended mode.

ANSI

Extended Mode

SQLERROR

SQLERROR

NOT FOUND

NOT FOUND

 

SQLWARNING

Following are the exception actions for ANSI mode and extended mode.

ANSI

Extended Mode

GOTO target

GOTO target

GO TO target

GO TO target

CONTINUE

CONTINUE

GOTO and GO TO cause transfer of control to the target paragraph or section.

CONTINUE causes the program to continue execution with the next COBOL statement.

The scope of an exception declaration:

Note: SQL statements occurring in the source before an exception declaration are not affected by it.

Any SQL statements executed that are not under control of an exception declaration default to CONTINUE.

If an exception declaration is not provided, the recommended practice is that your program include code to check the SQLCODE value in the SQL Communication Area (SQLCA) immediately after each executable SQL statement.

Executable SQL Statements in COBOL

Executable SQL statements must appear in the PROCEDURE DIVISION in the following format:

EXEC SQL

     statement

END-EXEC

Executable embedded SQL statements can appear anywhere that a COBOL statement can appear.