The bounds of an array determine the way elements of the array can be referred to. For example, when the following data items:
20 5 10 30 630 150 310 70
are assigned to the array List, as declared above, the different elements are referred to as follows:
Each of the parenthesized numbers following LIST is a subscript. A parenthesized subscript following an array name reference identifies a particular data item within the array. A reference to a subscripted name, such as LIST(4), refers to a single element and is an element variable. The entire array can be referred to by the unsubscripted name of the array--for example, LIST.
The same data can be assigned to List_A and List_B declared previously. In this case it is referenced as follows:
| Reference | Element | Reference |
|---|---|---|
| LIST_A (4) | 20 | LIST_B (-4) |
| LIST_A (5) | 5 | LIST_B (-3) |
| LIST_A (6) | 10 | LIST_B (-2) |
| LIST_A (7) | 30 | LIST_B (-1) |
| LIST_A (8) | 630 | LIST_B (0) |
| LIST_A (9) | 150 | LIST_B (1) |
| LIST_A (10) | 310 | LIST_B (2) |
| LIST_A (11) | 70 | LIST_B (3) |
Assume that the same data is assigned to TABLE, which is declared as a two-dimensional array. TABLE can be illustrated as a matrix of four rows and two columns:
| TABLE(m,n) | (m,1) | (m,2) |
|---|---|---|
| (1,n) | 20 | 5 |
| (2,n) | 10 | 30 |
| (3,n) | 630 | 150 |
| (4,n) | 310 | 70 |
An element of TABLE is referred to by a subscripted name with two parenthesized subscripts, separated by a comma. For example, TABLE (2,1) would specify the first item in the second row, the data item 10.
The use of a matrix to illustrate TABLE is purely conceptual. It has no relationship to the way the items are actually organized in storage. Data items are assigned to an array in row major order. This means that the subscript that represents columns varies most rapidly. For example, assignment to TABLE would be to TABLE(1,1), TABLE(1,2), TABLE(2,1), TABLE(2,2), and so forth.
A subscripted reference to an array must contain as many subscripts as there are dimensions in the array.
Any expression that yields a valid arithmetic value can be used for a subscript. If necessary, the value is converted to FIXED BINARY (with a precision corresponding to the CMPAT compiler option). Thus, TABLE(I,J*K) can be used to refer to the different elements of TABLE by varying the values of I, J, and K.