Skip to main content

RTS 153 Subscript out of range but subscript value is 1

  • February 15, 2013
  • 0 replies
  • 0 views

This article explains how to resolve the RTS 153 error.

Problem:

Given an Array which uses OCCURS depending on the value of a numeric variable to determine the size of the array. The current subscript value is far less than the value last moved to the variable which controls the number of occurrences.

01 BIG-ARRAY PIC X OCCURS

0 TO 1500000 DEPENDING ON OCCURS-NUMBER.

01 SUBSCRIPTING-VARIABLE PIC 9(8).

01 OCCURS-NUMBER PIC 9(6).

MOVE 1000000 TO OCCURS-NUMBER.

MOVE 1 TO SUBSCRIPTING-VARIABLE.

(Program terminates with RTS 153, subscript out of range).

Resolution:

OCCURS-NUMBER is too small to hold its maximum possible value, which is a seven-digit number. The statement MOVE 1000000 TO OCCURS-NUMBER actually overflowed the variable and was truncated. Therefore, the value of OCCURS-NUMBER is zero, due to the truncation rules for the MOVE statement.

The solution is to make OCCURS-NUMBER seven or more digits by editing the PIC clause in its declaration.

Old KB# 13983