If LIBEXIT is specified, the compiler loads the exit module (mod2) during initialization. The compiler makes calls to the module to obtain copybooks whenever COPY or BASIS statements are encountered.
Use LIB: If LIBEXIT is specified, the LIB compiler option must be in effect.
The first call invokes the module with an OPEN op code. The module can then prepare the specified library-name for processing. The OPEN op code is also issued the first time a new library-name is specified. The exit module returns the status of the OPEN request to the compiler by passing a return code.
When the exit invoked with the OPEN op code returns, the exit module is then invoked with a FIND op code. The exit module establishes positioning at the requested text-name (or basis-name) in the specified library-name. The requested item becomes the "active copybook". When positioning is complete, the exit module passes an appropriate return code to the compiler.
The compiler then invokes the exit module with a GET op code, and the exit module passes the compiler the length and address of the record to be copied from the active copybook. The GET operation is repeated until the end-of-data indicator is passed to the compiler.
When end-of-data occurs, the compiler issues a CLOSE request so that the exit module can release any resources related to its input.
Nested COPY statements: Any record from the active copybook can contain a COPY statement. (However, nested COPY statements cannot contain the REPLACING phrase, and a COPY statement with the REPLACING phrase cannot contain nested COPY statements.) When a valid nested COPY statement is encountered, the compiler issues one of the following requests:
Recursive calls cannot be made to text-name. That is, a copybook can be named only once in a set of nested COPY statements until the end-of-data for that copybook is reached.
When the exit module receives the OPEN or FIND request, it should push its control information about the active copybook onto a stack and then complete the requested action (OPEN or FIND). The newly requested text-name (or basis-name) becomes the active copybook.
Processing continues in the normal manner with a series of GET requests until the end-of-data indicator is passed to the compiler.
At end-of-data for the nested active copybook, the exit module should pop its control information from the stack. The next request from the compiler will be a FIND, so that the exit module can reestablish positioning at the previous active copybook.
The compiler then invokes the exit module with a GET request, and the exit module must pass the same record that was passed previously from this copybook. The compiler verifies that the same record was passed, and then the processing continues with GET requests until the end-of-data indicator is passed.
The compiler uses a structure, passed by reference, to communicate with the exit module.
related references
Parameter list for exit modules