Subscript
- The number of occurrences of an array element is called as subscript.
- A separate element of a table is accessed by using the subscript.
- It starts from 1 and to refer to the next occurrence it increases one by one.
- The subscript value can be any positive number.
- It is automatically created with OCCURS clause, so that it does not need any declaration in data division.
Example : Program to demonstrate subscript
IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-TABLE.
05 WS-A OCCURS 3 TIMES.
10 WS-B PIC 9(4).
10 WS-C OCCURS 2 TIMES.
15 WS-D PIC X(2).
PROCEDURE DIVISION.
MOVE 'tutorialridecareerride198859' TO WS-TABLE.
DISPLAY 'WS-TABLE : ' WS-TABLE.
DISPLAY 'WS-A(1) : ' WS-A(1).
DISPLAY 'WS-C(1,1) : ' WS-C(1,1).
DISPLAY 'WS-C(1,2) : ' WS-C(1,2).
DISPLAY 'WS-A(2) : ' WS-A(2).
DISPLAY 'WS-C(2,1) : ' WS-C(2,1).
DISPLAY 'WS-C(2,2) : ' WS-C(2,2).
DISPLAY 'WS-A(3) : ' WS-A(3).
DISPLAY 'WS-C(3,1) : ' WS-C(3,1).
DISPLAY 'WS-C(3,2) : ' WS-C(3,2).
STOP RUN.
Output:
WS-TABLE : tutorialridecareerride19
WS-A(1) : tutorial
WS-C(1,1) : ri
WS-C(1,2) : al
WS-A(2) : ridecare
WS-C(2,1) : ca
WS-C(2,2) : re
WS-A(3) : erride19
WS-C(3,1) : de
WS-C(3,2) : 19


