Subscripting COBOL

Subscripts are used when reference is made to an individual element within a table of like elements that have not been assigned individual data-names.

Subscripting

Except as the subject of a SEARCH statement, in a REDEFINES clause, or in a KEY IS phrase of an OCCURS clause, every reference to a table element must be subscripted, and there must be within the parentheses exactly as many subscripts as there are controlling OCCURS clauses for the data item referred to by data-name-1 or the conditional variable associated with condition-name-1.

A data item is controlled by an OCCURS clause if the OCCURS clause is in the data description of the data item or in the data description of a higher-level data item to which the data item is subordinate. A table element is a data item that has at least one controlling OCCURS clause.

Each subscript in the list is associated with a specific OCCURS clause that appears either in the data description of data-name-1 itself or at a higher level within the same hierarchy. When there is more than one subscript in the parenthesized list, the subscripts are written in the order of successively less inclusive dimensions of the table. That is, the rightmost subscript in the list is associated with the OCCURS clause that appears in the data description of data-name-1 itself, or the nearest preceding OCCURS clause, if the data description of data-name-1 does not contain an OCCURS clause.

The value of each subscript is an occurrence number. The lowest possible occurrence number is 1, and an occurrence number of 1 refers to the first element of the table. Higher occurrence numbers (2, 3, . . .) refer in sequence to the following elements of the table. The highest permissible occurrence number for any given dimension of the table is the maximum number of occurrences of the item as specified in the associated OCCURS clause.

The syntax for each individual subscript is:

syntax for each individual subscript

integer-1 may be signed, but only with a plus sign.When the integer-1 form of a subscript is used, the occurrence number is the value of integer-1.

When the data-name-2 form of a subscript is used, data-name-2 may be qualified but not subscripted. It must be defined in the Data Division as a numeric integer data item. The value of the occurrence number of the subscript is the current value of the data item referred to by data-name-2 optionally incremented (when the + is used) or decremented (when the – is used) by the value of integer-2.The value of integer-2 may be zero. Note that when the integer-2 option is present, the sum (or difference) of the current value of the data item and integer-2 must be a valid occurrence number. The user is responsible for ensuring that the current value of the data item referred to by data-name-2 is appropriate for this use of data-name-2 . The value of the data item can be modified by a number of different statements such as the MOVE statement, arithmetic statements, and so forth.

When the index-name-1 form of a subscript is used, the OCCURS clause that is associated with the subscript must specify an INDEXED BY phrase, and index-name-1 must be defined in the list of that INDEXED BY phrase.

The value of the occurrence number of the subscript is the occurrence number contained in the index referred to by index-name-1 optionally incremented (when the + is used) or decremented (when the– is used) by the value of integer-2. The value of integer-2 may be zero. Note that when the integer-2 option is present, the sum (or difference) of the current value of the index and integer-2 must be a valid occurrence number. The user is responsible for ensuring that the current value of the index referred to by index-name-1 is appropriate for this use of index-name-1. The value of an index can be modified only by the SET statement and by certain forms of the PERFORM and SEARCH statements.

When it is convenient to do so, the integer-1 or index-name-1 form of a subscript should be used in preference to the data-name form, for efficiency.



Face Book Twitter Google Plus Instagram Youtube Linkedin Myspace Pinterest Soundcloud Wikipedia

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

COBOL Topics