Using reference modification you can easily reference an area of memory that lies outside the named data item. The results of illegal reference modification depend on the location of the area of memory that your program accesses:
In the example below, the reference modification results in RTS error 114 ("Attempt to access item beyond bounds of memory") when run. This is caused by setting a to be greater than the maximum length of b. The first use of a reference modified item is a source field, so results in incorrect data being passed into c. This problem is detected by this COBOL system.The second use of a reference modified item is potentially more dangerous, as the reference modified item is a target field. Again, this COBOL system detects this problem and produces RTS error 114 ("Attempt to access item beyond bounds of memory").This example is used in the following sections to illustrate how to debug the program in various environments.
program-id. "buggy". working-storage section. 01 a pic 9(6). procedure division. move 999999 to a call "bug" using a stop run. end program "buggy". program-id. "bug". working-storage section. 01 b pic x(20). 01 c pic x. linkage section. 01 a pic 9(6). procedure division using a. move b(a:1) to c move "1" to b(a:1) exit program.