Skip to content
systemcoding.dev
Mainframe

Turn on runtime subscript checks with SSRANGE

Turn on runtime subscript checks with the SSRANGE compiler option, so a bad index stops the run with a message.

1 min read
Summarize in AI

By default Enterprise COBOL for z/OS 6.4 does not check table subscripts, so a subscript past the end of a table reads or overwrites the storage after it. The SSRANGE compiler option adds a check to every reference.

cobol
CBL SSRANGE
       IDENTIFICATION DIVISION.
       PROGRAM-ID. RANGECHK.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  WS-TAB.
           05  WS-ENTRY   PIC 9 OCCURS 3 TIMES.
       01  WS-I           PIC 9 VALUE 4.
       PROCEDURE DIVISION.
           MOVE 1 TO WS-ENTRY (WS-I)
           STOP RUN.
Text
IGZ0006S The reference to table WS-ENTRY by verb number 1 on line 10 addressed an area outside the region of the table.

The table has three entries and the subscript is 4, so the check fails and the run ends with this message and a Language Environment abend. The line number is the source line of the MOVE in this listing, and yours will differ.

The check also needs the runtime option CHECK(ON), which is the default, so a site that sets CHECK(OFF) loses it. Every checked reference costs extra instructions, so many shops compile with SSRANGE in test and without it in production. It does not check reference modification unless the same option is on, and then it applies to those too.

Share

More snippets

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.