When attempting to access a multi-dimensional table outside of its subscript range, a “subscript out of range” error is not always generated at runtime.
Given an array M_TABLE:
01 M_TABLE OCCURS 8.
02 D-TABLE OCCURS 8.
03 TABLE_DATA PIC X(5).
And the Procedure Division statement:
MOVE “DATA” TO TABLE_DATA (x, y).
If the values of x and y were 1 and 9 respectively, a ‘subscript out of range’ error is not generated at runtime even though the value in y is greater than the second dimension of the table.
The compiler directives that affect subscripting are SSRANGE and BOUND.
The comments in the BOUND section state:
For multi-dimensional tables, only the composite subscript is checked. If any of the individual subscripts or indices is beyond its limit, but the reference remains within the table, no error is produced.
In the example above, as the combined subscript (ie 1,9) is still within the physical bounds of the array, no error is produced at runtime, and the data will still be stored within the tables boundaries. This action means that any data already stored in the table could be overwritten and lost. Unpredictable results may be obtained when this area of the table is accessed further in the program.
As the Micro Focus compiler and run time processor can allow an individual subscript of a multi-dimensional table to be outside the range of its own occurrence, it is recommended that checking of subscripts is always coded to ensure this situation does not occur.
For example, in the above table:
IF (x < 1 OR > 8)
OR (y < 1 OR > 8)
GO TO EXIT_PARA