Operating System - Linux
1820879 Members
5398 Online
109628 Solutions
New Discussion юеВ

Cobol - 153 Subscript out of range

 
SOLVED
Go to solution
Alex Fedyashov
Occasional Advisor

Cobol - 153 Subscript out of range

I have almost no experience with Cobol. We moved existing Cobol code to a new server a compiled it there. The program works with most files but fails somewhere towards the end on others. According to the debugger it fails on a MOVE. Any help would be appreciated.

10 RPT1-FIELD-NAME PIC X(25).
77 WS-RPT-SUB PIC 9(6) VALUE 1.

MOVE 'FFV DEPT ID/GL: ' TO
RPT1-FIELD-NAME(WS-RPT-SUB)

Thanks,
Alex
4 REPLIES 4
James R. Ferguson
Acclaimed Contributor

Re: Cobol - 153 Subscript out of range

Hi ALex:

Cobol array subscripts range from one (1) to n. What you show is only that the *initial* value of WS-PRT-SUB is one which would be valid if RPT1-GIELD-NAME is subordinate to an 'OCCURS' clause.

Addressing outside of the range of occurances that constitute an array (n < 1 or n > nbr_elements) will result in a fault.

Regards!

...JRF...
Alex Fedyashov
Occasional Advisor

Re: Cobol - 153 Subscript out of range

Hi James,
Could you explain that a little differently, maybe even show me how it should look? Thanks for your help.
James R. Ferguson
Acclaimed Contributor
Solution

Re: Cobol - 153 Subscript out of range

Hi Alex:

Consider (in general):

01 MYTABLE.
03 MYCHARS OCCURS 5 TIMES.
05 CHAR PIC X(1).

...in memory, looks like:

[_][_][_][_][_]
1 2 3 4 5

...and thus we can say:

MOVE "h" TO CHAR(1).
MOVE "i" TO CHAR(2).

[h][i][_][_][_]
1 2 3 4 5

...but if we try:

MOVE "x" TO CHAR(6).

...we fault, because we have tried to write beyond the array bounds -- into memory that doesn't "belong" to us. Similarly, if we were to try:

MOVE "x" to CHAR(0).

Is that the explanation you wanted?

Regards!

...JRF...
Alex Fedyashov
Occasional Advisor

Re: Cobol - 153 Subscript out of range

Hey James,
Thanks for the help.