3. Embedded SQL for COBOL : COBOL Data Items and Data Types : Variable Usage : COBOL Tables
 
Share this page                  
COBOL Tables
To refer to a COBOL table, use the following syntax:
:tablename(subscript{,subscript})
Syntax Notes:
You must subscript the tablename because only elementary data items are legal SQL values.
When you declare a COBOL table, the preprocessor notes from the OCCURS clause that it is a table and not some other data item. When the table is later referenced in an ESQL statement, the preprocessor confirms that a subscript is present but does not check the legality of the subscript inside the parentheses. Consequently, you must ensure that the subscript is legal and that the correct number of subscripts is used.
If you use COBOL tables as null indicator arrays with COBOL record assignments, do not include subscripts.
The following example uses the variable SUB1 as a subscript that does not need to be declared in the embedded SQL declaration section because the preprocessor ignores it.
Example: COBOL table usage
EXEC SQL BEGIN DECLARE SECTION END-EXEC.
01 FORMNAMES.
  02 FORM-TABLE PIC X(8) OCCURS 3 TIMES.

EXEC SQL END DECLARE SECTION END-EXEC.

01 SUB1 PIC S9(4) USAGE COMP VALUE ZEROES.

PROCEDURE DIVISION.
BEGIN.
* Program code

PERFORM VARYING SUB1 FROM 1 BY 1
   UNTIL SUB1 > 3

EXEC FRS FORMINIT :FORM-TABLE(SUB1) END-EXEC

END-PERFORM.

* More program code.