Problem:
If a calling program calls a program without passing all parameters defined in Linkage section (of called program), then the runtime system may fail with runtime error 114. This will happen when the called program references any LINKAGE SECTION field that has not received a parameter.
For example, the following is code in the calling program:
CALL "SUBPROG" USING WS-AREA
WS-KEY
where the called program has a LINKAGE SECTION defined with CALL-AREA, START-AREA and CALL-KEY. In this case it would seem nothing equivalent to START-AREA is passed to the called program.
Resolution:
By default COBOL calls 'by reference' - which means only a memory address is passed to the called program, not data.
This means that data changed in the called program is directly reflected in the calling program as they are both accessing the same location in memory. Therefore, nothing has to be passed back.
Passing by reference essentially means that there is no 'end' address for what is being passed. What actually determines where the data field ends is the length of the receiving field in the LINKAGE SECTION of the called program. However, it is the length of the group level 01 item that determines the end memory address, not sub levels eg 03, 05 etc.
If the LINKAGE SECTION of the called program was defined as follows:
LINKAGE SECTION.
01 CALL-AREA PIC X(20).
01 START-AREA PIC X(20).
01 CALL-KEY PIC 9(3).
...
PROCEDURE DIVISION USING CALL-AREA, START-AREA, CALL-KEY
but the call from the calling program was specified as:
CALL "SUBPROG" USING WS-AREA
WS-KEY
it would pass the memory address for WS-AREA to CALL-AREA and then the memory address for WS-KEY to START-AREA.
CALL-KEY in the called program would remain unassigned. Any attempt to reference CALL-KEY in the called program would result in an unassigned memory error, probably causing a 114 code at runtime.
If, however, the LINKAGE SECTION of the called program was defined as follows:
LINKAGE SECTION.
01 CALL-AREA.
05 START-AREA PIC X(20).
01 CALL-KEY PIC 9(3).
...
PROCEDURE DIVISION USING CALL-AREA, CALL-KEY
and the call from the calling program was specified as:
CALL "SUBPROG" USING WS-AREA
WS-KEY
then the address on WS-AREA would be passed to the 01 level CALL-AREA and the address of WS-KEY would be passed the next 01 level, WS-KEY. In this case referencing WS-KEY in the called program would result in an error as it has received a memory address from the calling program.
It is essential that the specification of the data being passed and the data being received in the LINKAGE SECTION match exactly and all passed/receiving fields correlate. Anything else is bad coding and potentially opens the possibility for 114 memory related errors.