COBOL Array/Table SubscriptCOBOL Array/Table COBOL Table Index
Number of occurrences of array element is called as Subscript.
Take the above memory representation Diagram to understand better about Subscript.
01 BTECH-1ST-YEAR. 02 STUDENT. 03 SUBJECT-MARKS PIC 9(03) OCCURES 6 TIMES.
The OCCURRENCES in the above diagram is Subscript.
Subscript will not refer the memory positions but the subscript refers the position of array element where the element exists.
Subscript should be defined in a Working-storage section with S9(04) COMP.
In the above examples, SUBJECT-MARKS have 6 OCCURRENCES. i.e. Subscript have 6 occurrences from 1 to 6.
Subscript always starts from 1 and increase one by one to refer the next occurrence of element.
Subscript needs to be initialized always to 1 and needs to be incremented or can be initialized to max occurrence of array element and can be decremented.
Here, Incrementing subscript by 1 increments the single occurrence of array element.
The element can be referred like below in programming construction.
COBOL Array/Table COBOL Table Index