BEGIN DECLARE SECTION

Signals the beginning of the DECLARE section.

Syntax:

>>---EXEC SQL---BEGIN DECLARE SECTION---END-EXEC---><

Comments:

The BEGIN DECLARE SECTION statement can be included anywhere where COBOL permits variable declaration. Use END DECLARE SECTION to identify the end of a COBOL declaration section.

  • Declare sections cannot be nested.
  • Variables must be declared in COBOL, not in SQL.
  • To avoid conflict, variables inside a declaration section cannot be the same as any outside the declaration section or in any other declaration section, even in other compilation units.

If data structures are defined within a declaration section, only the bottom-level items (with PIC clauses) can be used as host variables. Two exceptions are arrays specified in FETCH statements and record structures specified in SELECT INTO statements.

Example:

 WORKING-STORAGE SECTION.
 EXEC SQL BEGIN DECLARE SECTION END-EXEC
 01 staff-id        pic x(4).
 01 last-name       pic x(30).
 EXEC SQL END DECLARE SECTION END-EXEC