Subscripting

Subscripting is a method of providing table references through the use of positive integers. A subscript is a positive integer (or integer data item) whose value specifies the occurrence number of a table element.

Read syntax diagramSkip visual syntax diagram
Subscripting - Format

                         .-------------------------.   
                         V                         |   
>>-+-condition-name-1-+----+---------------------+-+------------>
   '-data-name-1------'    '-+-IN-+--data-name-2-'     
                             '-OF-'                    

>--+---------------------+-------------------------------------->
   '-+-IN-+--file-name-1-'   
     '-OF-'                  

      .-----------------------------------------.      
      V                                         |      
>--(----+-integer-1---------------------------+-+--)-----------><
        +-ALL---------------------------------+        
        +-data-name-3--+-------------------+--+        
        |              '-+-+--+--integer-2-'  |        
        |                '- --'               |        
        '-index-name-1--+-------------------+-'        
                        '-+-+--+--integer-3-'          
                          '- --'                       

condition-name-1
Must be subordinate to a data description entry which contains an OCCURS clause.
data-name-1
Must contain an OCCURS clause or must be subordinate to a data description entry which contains an OCCURS clause.
integer-1
Can be signed. If signed, it must be positive.
ALL
Used as a function argument for a function that allows a variable number of arguments. Can be used only when the subscripted identifier is used as a function argument and can not be used when condition-name is specified.
data-name-3
Must be a numeric elementary item representing an integer.

Data-name-3 can be qualified.

index-name-1
Corresponds to a data description entry in the hierarchy of the table being referenced which contains an INDEXED BY phrase specifying the index-name.
integer-2, integer-3
Must be an unsigned integer.

The subscripts, enclosed in parentheses, are written immediately following any qualification for the name of the table element. The number of subscripts in such a reference must equal the number of dimensions in the table whose element is being referenced. That is, there must be a subscript for each OCCURS clause in the hierarchy containing the data-name including the data-name itself.

When more than one subscript is required, they are written in the order of successively less inclusive dimensions of the data organization. If a multi-dimensional table is thought of as a series of nested tables and the most inclusive or outermost table in the nest is considered to be the major table with the innermost or least inclusive table being the minor table, the subscripts are written from left to right in the order major, intermediate, and minor.

For example, if TABLE-THREE is defined as:
01  TABLE-THREE.
    05  ELEMENT-ONE OCCURS 3 TIMES.
        10  ELEMENT-TWO OCCURS 3 TIMES.
            15  ELEMENT-THREE OCCURS 2 TIMES    PIC X(8).
a valid subscripted reference to TABLE-THREE is:
ELEMENT-THREE (2 2 1)

A reference to an item must not be subscripted unless the item is a table element or an item or condition-name associated with a table element.

Each table element reference must be subscripted except when such a reference appears:
  • In a USE FOR DEBUGGING statement
  • As the subject of a SEARCH statement
  • In a REDEFINES clause
  • In the KEY IS phrase of an OCCURS clause
  • In a LIKE clause

The lowest permissible occurrence number represented by a subscript is 1. The highest permissible occurrence number in any particular case is the maximum number of occurrences of the item as specified in the OCCURS clause.