── LINKLIBRARY ── ( ─┬─<library identifier>─────────────────────┬──────►
├─<connection library identifier>──────────┤
├─<connection library instance designator>─┤
├─<this intrinsic>─────────────────────────┤
└─<connection parameter>───────────────────┘
►─┬─<indirect linkage>───────┬─ ) ─────────────────────────────────────┤
├─<process family linkage>─┤
└─<direct linkage>─────────┘<indirect linkage>
──┬─────────────────────────┬──────────────────────────────────────────►
└─ , ─┬─ WAITFORFILE ─────┤
├─ DONTWAITFORFILE ─┤
└─ DONTWAIT ────────┘
►─┬───────────────────────────────────────────────────────────┬────────┤
│ ┌◄──────────────────────────────────────────────────────┐ │
└─┴─ , ─┬─/1\─ TITLE ─────────┬─ = ──<pointer expression>─┴─┘
├─/1\─ FUNCTIONNAME ──┤
└─/1\─ INTERFACENAME ─┘
<process family linkage>
── , ── PROCESS VIA ──<process family designator>──────────────────────► ►─┬──────────────────────────────────────────────────┬─────────────────┤ └─ , ── INTERFACE NAME ── = ──<pointer expression>─┘
<direct linkage>
── , ── LIBRARY ── = ─┬─<library identifier>────────────┬──────────────┤
├─<connection library identifier>─┤
├─<connection library designator>─┤
├─<task designator>───────────────┤
├─<this intrinsic>────────────────┤
└─<connection parameter>──────────┘
<process family designator>
──┬─<library identifier>─────────────────────┬─────────────────────────┤ ├─<connection library identifier>──────────┤ └─<connection library instance designator>─┘
The LINKLIBRARY function determines whether or not the program is currently linked to, or is capable of being linked to, the library program specified by the library designator. Results indicating a successful linkage are returned by the LINKLIBRARY function if the program is presently linked to the library or if the program is capable of being linked, in which case the LINKLIBRARY function performs the linkage. If the program cannot be linked to the library, the function returns a result indicating the reason for the failure. Whether or not linkage is achieved, the program continues to execute; that is, the use of the LINKLIBRARY function prevents the termination or suspension of a program upon an unsuccessful attempt to link to a library.
During the linkage process, an attempt is made to link to every entry point exported from the library whose name matches an entry point declared in the program. Only those names that match are checked for correct function type, number of parameters, and parameter types. Therefore, the LINKLIBRARY function does not check that every entry point exported from the library is declared in the program.
Indirect Linkage
If the WAITFORFILE option is set, it causes the stack to wait on an RSVP message. The WAITFORFILE option is also passed to the APPROVAL procedure of a connection library as the WAIT parameter in case the APPROVAL procedure is waiting before granting approval. If the DONTWAITFORFILE option is set, an error is returned if the library code file is not available. If the DONTWAIT option is specified, the caller is linked to the library only if the library is immediately available, that is, if it is already FROZEN or readied by the READYCL intrinsic. If the library is not immediately available, an error result is returned. Use of the DONTWAIT option never results in the initiation of the codefile containing target library.
The LINKLIBRARY function uses the TITLE, FUNCTIONNAME, or INTNAME value, depending on the LIBACCESS value, to find the process family to link to. If a TITLE is specified, the operating system overrides the LIBACCESS to BYTITLE for this request. Similarly, if a FUNCTIONNAME is specified, the operating system overrides the LIBACCESS to BYFUNCTION for this request. If both TITLE and FUNCTIONNAME are specified, the operating system uses the LIBACCESS attribute value assigned to the library. The LINKLIBRARY function then searches for a connection library with a matching INTERFACENAME that has been marked ready for linkage by the READYCL intrinsic. If a match is found, a linkage to that connection library is attempted. If a matching connection library is not found, and the parent stack of that process family is a server library provider, the LINKLIBRARY function attempts to link to that server library provider.
Process Family Linkage
The PROCESS VIA syntax enables a client or connection library to link to the same process family to which another client or connection library is already linked.
The LINKLIBRARY function links the first parameter in the LINKLIBRARY call to the server library or connection library identified by the process family designator. This library specified by the process family designator must be linked to the server library or connection library, and this library must have a sharing specification of SHAREDBYALL.
Examples of the PROCESS VIA syntax are as follows:
LINKLIBRARY (LIB1, PROCESS VIA LIB2);
EBCDIC ARRAY NAME [0:255];
REPLACE NAME BY "MYINTERFACE";
LINKLIBRARY (LIB1, PROCESS VIA LIB2, INTERFACENAME = NAME);
Direct Linkage
A direct linkage establishes linkage between two libraries that are specified in the LINKLIBRARY invocation. The linkage is the same as an indirect linkage, except that the TITLE, FUNCTIONNAME, INTERFACENAME, and LIBACCESS attribute values are irrelevant. If a task identifier is given in a direct linkage, the task must be for a frozen library. If the first parameter is a library identifier, then the second parameter must not be a library identifier.
The APPROVAL procedure associated with the library of the first parameter is invoked only if that parameter is a connection library identifier and only if it identifies a multiple-connection connection library. For more information on initiating connection library linkage and on the APPROVAL procedure, see the Task Management Programming Guide.
Value Returned
The values returned by the LINKLIBRARY function can be interpreted as follows:

