 <p>Presuming that by Host you mean Mainframe, using Enterprise COBOL, the link I originally included has the answer for you.</p> <p>In Enterprise COBOL, you can use an index from one table to reference data on another table, even one which does not have an index (like your example), but <em>unless the lengths of the data subordinate to the OCCURS is the same</em> you will not get the results you expect.</p> <p>With Enterprise COBOL and compiler option SSRANGE the code in your question will fail (as you are aware). Where will it fail? The length of the OCCURS associated with the index S-SUB is eight bytes. That length is effectively "inbuilt" into the index S-SUB. Dividing 999 (length of second table) by eight yields 124 (ignore the remainder), so an S-SUB being SET to 124 will be OK, and SET to 125 will not, because 125 will start at by 1,000, and you only have 999 bytes.</p> <p>In GnuCOBOL the index does not have the length inbuilt, it is a simple integer relating directly to the occurence in the table. However, having got up to 100, you start overflowing the first table (where there is no compiler/run-time check) and 125 references later you go beyond the end of the second table, and with -g in your compile options will get a crash depending on how (and how much) the storage is allocated in the C program generated by the GnuCOBOL compiler. 225 would be the first point at which a crash could occur, but it may not do so at that point, and it may, or may not, later.</p> <p>Basically, there's no way you can really expect the code to work, which you know, you just want to know how to set the compiler to check for it with GnuCOBOL. Currently, you can't.</p> <p>Usually there is a field defined to hold the maximum entries in a table, and another defined to say how many are being used. When using entries, you first check to see the table is not full.</p> <p>You could use <code>LENGTH OF</code>/<code>FUNCTION LENGTH</code> to protect against going over the end of a table as well.</p> <p>You could combine the two approaches.</p> <p>You just don't have a switch for GnuCOBOL that helps you here. The <code>-g</code> goes down to the C compiler. It gives you something, but not everything, and just depends.</p> <p>Also, it is not, to my mind, a good idea to have a data-name which you use for subscripting named <code>IX</code> and an index named <code>S-SUB</code>. That will confuse a human reader of a program.</p> <p>See this answer: <a href="http://stackoverflow.com/a/36254166/1927206">http://stackoverflow.com/a/36254166/1927206</a> for some detail about using indexes from different tables.</p> <p>IBM Enterprise COBOL can check that storage referenced using an index is within the table that the referenced-element is subordinate to. This is done with compiler option SSRANGE. If data outside the table is referenced (by any manner of subscripting, or by reference-modification) a run-time diagnostic message is produced. In all but the latest Enterprise COBOL compilers, that problem will cause an "abend" (an "abnormal end"). With the latest compilers, there are some sub-options to give more control.</p> <p>This is not strictly checking the "bounds" of a table. For a one-dimensional table, the table-reference checking coincides with bounds-checking. For a multi-dimensional table it does not. The second and subsequent levels of subscript can be "wrong", but unless they cause a reference outside the table, this is unproblematic.</p> <p>GnuCOBOL/OpenCOBOL does not have any checking for the use of subscripts or the reference of a table by subscripting/reference-modification. If you wanted to consider adding this yourself, you would be more than welcome. Or you could post it as a feature request. Visit <a href="https://sourceforge.net/p/open-cobol/discussion/?source=navbaring" rel="nofollow">https://sourceforge.net/p/open-cobol/discussion/?source=navbaring</a>, but not everything.</p> <p>See this answer: <a href="http://stackoverflow.com/a/36254166/1927206">http://stackoverflow.com/a/36254166/1927206</a> for some detail about using indexes from different tables.</p> <p>IBM Enterprise COBOL can check that storage referenced using an index is within the table that the referenced-element is subordinate to. This is done with compiler option SSRANGE. If data outside the table is referenced (by any manner of subscripting, or by reference-modification) a run-time diagnostic message is produced. In all but the latest Enterprise COBOL compilers, that problem will cause an "abend" (an "abnormal end"). With the latest compilers, there are some sub-options to give more control.</p> <p>This is not strictly checking the "bounds" of a table. For a one-dimensional table, the table-reference checking coincides with bounds-checking. For a multi-dimensional table it does not. The second and subsequent levels of subscript can be "wrong", but unless they cause a reference outside the table, this is unproblematic.</p> <p>GnuCOBOL/OpenCOBOL does not have any checking for the use of subscripts or the reference of a table by subscripting/reference-modification. If you wanted to consider adding this yourself, you would be more than welcome. Or you could post it as a feature request. Visit <a href="https://sourceforge.net/p/open-cobol/discussion/?source=navbar" rel="nofollow">https://sourceforge.net/p/open-cobol/discussion/?source=navbar</a></p>