Figure 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.
The program was run with TERMTHDACT(TRACE) to generate the traceback information shown in Sections of Language Environment dump for COBOLX.
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.
To understand the traceback information and debug this program, use the following steps:
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
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.