Created On:  04 March 2011

Problem:

You may receive the following error when attempting to access data in the LINKAGE SECTION in a called program:

114     Attempt to access item beyond bounds of memory (Signal 11)

You will receive this error if you access LINKAGE data that has not been assigned correctly. For example, assume program Call1 calls program Call2. But the LINKAGE SECTION in Call2 is larger (i.e. has more characters defined) than the parameters being passed by Call1.

Program Call1

Working-Storage Section.

01  Link-Param-1               Pic X(10).

Procedure Division

Call “Call2” Using Link-Param-1

Program Call2

Working-Storage Section.

01  Work-Field-1               Pic x(20).

Linkage Section.

01  Link-Data.

       05  Lnk-Data-1            Pic X(20).

Procedure Division Using Lnk-Data-1.

Move Lnk-Data-1 to Work-Field-1.

***

When you execute this line you might receive error code 114.  This might not have returned an error in older versions of COBOL. That isn’t a problem, until you try and access (eg MOVE) ANY data in the LINKAGE section in the called program (call2) that has not been assigned correctly (i.e. data that is beyond the length of the data that has been passed). COBOL calls are made using ‘by reference’, not ‘by value’ – so it passes the memory address of the fields in the calling program, not the actual value in the fields. Therefore, if you attempt to access any area beyond the length of the last data field being passed, it will be deemed unassigned memory.

Resolution:

The PROTECT-LINKAGE compiler directive extends the standard COBOL semantics so that the lengths of parameters can differ between the calling and the called program. Normally, the result of ignoring the constraints would give undefined results, possibly including severe errors such as protection violations or memory access faults. But, this restriction is lifted when the PROTECT-LINKAGE directive is set.

But even if this fixes the 114 memory violation error, it still means you have LINKAGE SECTION data that has not been correctly assigned in memory and therefore should be fixed. If you have multiple programs with different length parameters calling a common subroutine, then add an extra call parameter in the calling program to ensure the length of all call params exceeds the length of the Linkage Section in the called program. It doesn’t matter how much bigger it is, just as long as it is bigger.

One thing of note – there is a difference in behaviour between .int code and object code (.gnt/.so/executables).  For .int code error 203 is returned where as in object code error 114 is returned.
Incident #2505118