3. Embedded QUEL for COBOL : COBOL Variables and Data Types : Variable Usage : COBOL Tables
 
Share this page                  
COBOL Tables
The following syntax refers to a COBOL array or table:
tablename(subscript{,subscript})
Syntax Notes:
You must subscript the tablename because only elementary data items are legal EQUEL 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 you later reference the table, 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 are used.
In the following example, the variable "SUB1" is used as a subscript and does not need to be declared to EQUEL declaration section, because the preprocessor ignores it.
DATA DIVISION.
WORKING-STORAGE SECTION.

##   01  FORMNAMES.
##       02   FORM-TABLE     PIC X(8) OCCURS 3 TIMES.

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

PROCEDURE DIVISION.
BEGIN.

* Program code

     PERFORM VARYING SUB1 FROM 1 BY 1
           UNTIL SUB1 > 3

##         FORMINIT FORM-TABLE(SUB1).

     END-PERFORM.

* More program code.