|
5.2 Tables
Also known as an array in other languages, a table is a group of data associated with a single item name. To identify
pieces data (elements) within that table the item is given a subscript number which follows the name.
So, DISPLAY W-NAME (2) will give "Jones".
A 2-dimensional table uses two subscripts: ![]() So element (2, 4) will contain "1.1". To define the W-NAME (1-dimensional) table in the data division:
To define the SALES-TABLE (2-dimensional) table, just add another level to the group. Hence:
Table can be multi-dimensional, but always the last level will be the identifier name that is associated
with the subscripts and will have the PIC clause.
For the use of tables, see the League Table Program
in the Sample Code section.
Finally, don't try to refer to a table element that is of a greater value than that defined in the data
division, i.e. W-NAME (6) will cause a runtime error and terminate the program. It should be obvious that
a subscript should be a numeric literal or an identifier that is numeric.
The use of identifiers as subscripts is where tables are of most use, i.e. MONTHLY-SALES (INPUT-BRANCH, INPUT-MONTH).
| ||||