STICKY-LINKAGE

Makes parameters to the program remain linked during subsequent calls of the program.
Note: This directive is supported for native COBOL only.

Syntax:

>>-.---.-.------STICKY-LINKAGE--"integer"-.-><
   +-/-+ +----NO-STICKY-LINKAGE-----------+

Parameters:

integer Either 1 or 2

Properties:

Default: NOSTICKY-LINKAGE
Phase: Syntax check
$SET: Initial

Comments:

The purpose of the COBOL Linkage Section is to provide a linkage between a level 01 or level 77 data item declared in the Linkage Section (a linkage item) and some dynamically specified data item so that they appear to share the same storage area. The linkage is established by one of three means: a CALL program-name USING statement, a CALL entry-name USING statement, or a SET statement. The first mechanism is the standard one specified by ANSI. The other two are COBOL language extensions that are supported by this COBOL system.

In ANSI COBOL, the Linkage Section enables a called program to access the parameters passed to it by a CALL statement. The number of parameters in the USING phrase of the CALL statement must equal the number of parameters in the USING phrase of the PROCEDURE DIVISION header. Any level 01 or level 77 data item in the Linkage Section that does not appear in the USING phrase of the PROCEDURE DIVISION header must not be referenced.

The ENTRY statement is a COBOL language extension that provides an alternative entry point into a program. The ENTRY statement takes a USING phrase in the same way as the PROCEDURE DIVISION header, and, in a similar fashion, linkage items must not be referenced if they do not appear in the USING phrase associated with the entry-name by which the program was invoked.

The SET statement enables a POINTER value that identifies a storage location to be used to link a linkage item. Such a linkage item can then be referenced in order to reference the data held at that storage location.

The following details explain in conceptual terms when linkage items are linked and unlinked.

This COBOL system checks at run time when a linkage item is referenced, to ensure it is linked to a data item. It gives a run-time error if it is not linked to any storage location. To facilitate this check, on each invocation immediately before executing the first statement in the program, all linkage items are first unlinked and then linkage items that have corresponding parameters passed by the calling program are linked. This means that a linkage item in a called program that is linked to a data item by the SET statement does not remain linked on subsequent invocations of the program; the SET statement needs to be executed in each invocation.

Many other COBOL implementations are less rigorous in enforcing the ANSI rules and the STICKY-LINKAGE directive takes a parameter to specify two alternative and less rigorous regimes.

STICKY-LINKAGE"1" specifies that only the linkage items that appear in the USING phrase of the called program are unlinked; other linkage items retain any previous linkage. If the program was called using the program-name this is the USING phrase of the PROCEDURE DIVISION header. Otherwise, this is the USING phrase associated with the entry-point by which the program was invoked.

Under this regime, if the calling program provides insufficient parameters and a reference is made to a linkage item that appears in the USING phrase but has no corresponding parameter in the USING phrase of the CALL statement, a run-time error is still given.

STICKY-LINKAGE"2" specifies that, except when the program is in its initial state at startup or after it is referenced in a CANCEL statement, no linkage items are unlinked when the program is called. All linkage items retain any linkage established during previous invocations unless the calling program provides a parameter or a SET statement is used to change the linkage.

No particular implementation method is implied by this and indeed, on this COBOL system, emulating the non-ANSI conformant behavior using this directive can have a detrimental effect on program size and execution speed.

Example:

If the following program is compiled without the STICKY-LINKAGE directive and run, a run-time error 203, CALL parameter not supplied, is given after the second CALL statement passes control to "ent" and the DISPLAY statement references two linkage items that do not appear in the USING phrase of ENTRY "ent".

If the program is then compiled with STICKY-LINKAGE"1" and run, execution progresses until it fails again after the third CALL statement passes control to "sub" and the DISPLAY statement references a linkage item that does appear in the USING phrase of the PROCEDURE DIVISION header but has no corresponding parameter passed by the CALL statement.

If the program is compiled with STICKY-LINKAGE"2" and run, the program successfully executes to completion.

 program-id. main.
 working-storage section.
 01 param pic x value "a".
 procedure division.
     call "sub" using param
     call "ent"
     call "sub"
     stop run.
 end program main.

 program-id. sub.
 linkage section.
 01 link-1 pic x.
 01 link-2 pic x.
 procedure division using link-1.
     set address of link-2 to address of link-1
     display link-1 link-2
     exit program.

   entry "ent"
     display link-1 link-2
     exit program.

If STICKY-LINKAGE"2" is used for a called program, it can be called only by a COBOL program.