Subscript range error

Start of changeFigure 1 illustrates the error of using a subscript value outside the range of an array. This program was compiled with LIST, TEST, and SSRANGE. The SSRANGE compiler option causes the compiler to generate code that checks (during run time) for data that has been stored or referenced outside of its defined area because of incorrect indexing and subscripting. The SSRANGE option takes effect during run time. For COBOL V4R2 and prior releases, you can disable the check by specifying the CHECK(OFF) runtime option. For Enterprise COBOL V5.1 and later releases, the CHECK runtime option is ignored.End of change

The program was run with TERMTHDACT(TRACE) to generate the traceback information shown in Sections of Language Environment dump for COBOLX.

Figure 1. COBOL example of moving a value outside an array rangeStart of change
  CBL  LIST,SSRANGE,TEST
       ID DIVISION.
       PROGRAM-ID. COBOLX.
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       77  J     PIC 9(4) USAGE COMP.
       01  TABLE-X.
        02  SLOT PIC 9(4) USAGE COMP OCCURS 8 TIMES.
       PROCEDURE DIVISION.
           MOVE 9 TO J.
           MOVE 1 TO SLOT (J).
           GOBACK.
End of change

To understand the traceback information and debug this program, use the following steps:

  1. Locate the current error message in the Condition Information for Active Routines section of the Language Environment traceback, shown in Sections of Language Environment dump for COBOLX. The message is IGZ0006S The reference to table SLOT by verb number 01 on line 000011 addressed an area outside the region of the table. The message indicates that line 11 was the current COBOL statement when the error occurred. For more information about this message, see z/OS Language Environment Runtime Messages.
  2. Statement 11 in the traceback section of the dump occurred in program COBOLX.
  3. Find the statement on line 11 in the listing for program COBOLX, shown in Figure 2. This statement moves the 1 value to the array SLOT (J).
    Figure 2. COBOL listing for COBOLX
    PP 5655-G53 IBM Enterprise COBOL for z/OS  3.4.1               COBOLX    Date 02/14/2007  Time 14:58:58   Page     3                
      LineID  PL SL  ----+-*A-1-B--+----2----+----3----+----4----+----5----+----6----+----7-|--+----8 Map and Cross Reference           
    /* COBOLX                                                                                                                           
      000001                ID DIVISION.                                                                                                
      000002                PROGRAM-ID. COBOLX.                                                                                         
      000003                ENVIRONMENT DIVISION.                                                                                       
      000004                DATA DIVISION.                                                                                              
      000005                WORKING-STORAGE SECTION.                                                                                    
      000006                77  J     PIC 9(4) USAGE COMP.                                                                              
      000007                01  TABLE-X.                                                                                                
      000008                 02  SLOT PIC 9(4) USAGE COMP OCCURS 8 TIMES.                                                               
      000009                PROCEDURE DIVISION.                                                                                         
      000010                    MOVE 9 TO J.                                                          6                                 
      000011                    MOVE 1 TO SLOT (J).                                                   8 6                               
      000012                    GOBACK.                                                                                                 
    */ COBOLX
  4. Find the values of the local variables in the Parameters, Registers, and Variables for Active Routines section of the traceback, shown in Sections of Language Environment dump for COBOLX. J, which is of type PIC 9(4) with usage COMP, has a 9 value. J is the index to the array SLOT.

    The array SLOT contains eight positions. When the program tries to move a value into the J or 9th element of the 8-element array named SLOT, the error of moving a value outside the area of the array occurs.