Skip to main content
Modernization Hub

ASSRANGE - Array Boundary Violation in Production

Interview Question

"Code review scenario: You're reviewing a trainee's COBOL program that loads product pricing into an array:

01  PRICE-TABLE.
    05  PRICE-ENTRY OCCURS 5000 TIMES.
        10  PRODUCT-ID    PIC X(10).
        10  UNIT-PRICE    PIC 9(5)V99 COMP-3.

PROCEDURE DIVISION.
    PERFORM LOAD-PRICES
    PERFORM CALCULATE-TOTALS.

LOAD-PRICES.
    OPEN INPUT PRICE-FILE
    MOVE 1 TO WS-INDEX
    PERFORM UNTIL END-OF-FILE
        READ PRICE-FILE INTO PRICE-ENTRY(WS-INDEX)
        ADD 1 TO WS-INDEX
    END-PERFORM.

Situation:

  • Program compiled without SSRANGE, tested with 100 records - worked fine
  • Moved to production, ran with 5,200 products
  • Program produced incorrect totals (no ABEND)
  • Financial reports showed wrong revenue figures
  • Discovered after month-end close

Questions:

1. What went wrong?

2. How would SSRANGE have helped?

3. What's the production impact?

4. How do you fix this immediately and long-term?"

What This Tests

  • Understanding of subscript checking
  • Quality assurance practices
  • Production readiness criteria
  • Defensive programming techniques

Good Answer Should Include

1. Root Cause:

  • Program processed 5,200 records but array only holds 5,000
  • After WS-INDEX = 5000, records 5,001-5,200 overwrote memory
  • Likely corrupted WS-TOTAL or other working storage variables
  • No ABEND because memory overwrite was in valid address space
  • Garbage values caused incorrect calculations

2. SSRANGE Impact:

  • With SSRANGE (or NOSSRANGE for production):
  • Program would ABEND immediately at WS-INDEX = 5001
  • S0C4 or 0E38 ABEND with subscript error message
  • Problem detected immediately, not after month-end

3. Immediate Fix:

LOAD-PRICES.
    OPEN INPUT PRICE-FILE
    MOVE 1 TO WS-INDEX
    PERFORM UNTIL END-OF-FILE OR WS-INDEX > 5000
        READ PRICE-FILE INTO PRICE-ENTRY(WS-INDEX)
        IF WS-INDEX < 5000
            ADD 1 TO WS-INDEX
        ELSE
            DISPLAY 'WARNING: Table overflow at record ' WS-INDEX
            PERFORM WRITE-ERROR-LOG
        END-IF
    END-PERFORM.

4. Long-term Solution:

  • Increase table size to 10,000 (allow for growth)
  • Or use dynamic table (OCCURS DEPENDING ON)
  • Or implement file-based processing (no table limit)
  • Establish testing standards: Test with MAX+1 records

5. Process Improvements:

  • Always compile with SSRANGE for testing
  • Test with boundary conditions (0 records, MAX records, MAX+1 records)
  • Code review checklist: Look for array processing
  • Add input record count validation

Red Flags

  • ❌ Doesn't understand why no ABEND occurred
  • ❌ Suggests just increasing array size without bounds checking
  • ❌ Doesn't mention testing implications
  • ❌ Can't explain difference between compile-time and runtime checking
  • ❌ Doesn't recognize this as a critical production issue

Follow-Up Questions

  • "Why didn't the program ABEND if it accessed invalid subscript?"
  • "What's the difference between SSRANGE and NOSSRANGE?"
  • "How much overhead does SSRANGE add? Would you use it in production?"
  • "What if you need to process unlimited records?"

Difficulty Level

Mid-Level

Relevant Roles

Developer, Code Reviewer, Technical Lead