The exit module is used in place of the SYSLIB, or library-name, data set. Calls are made to the module by the compiler to obtain copybooks whenever COPY or BASIS statements are encountered.
If LIBEXIT is specified, the LIB compiler option must be in effect.
| Action by compiler | Resulting action by exit module |
|---|---|
| Loads the exit module (mod2) during initialization | |
| Calls the exit module with an OPEN operation code (op code) | Prepares the specified library-name for processing. Passes the status of the OPEN request to the compiler. |
| Calls the exit module with a FIND op code if the library-name was successfully opened | Establishes positioning at the requested text-name (or basis-name) in the specified library-name; this place becomes the active copybook. Passes an appropriate return code to the compiler when positioning is complete. |
| Calls the exit module with a GET op code | Passes the compiler either the length and address of the record to be copied from the active copybook or the end-of-data indicator |
| Calls the exit module with a CLOSE op code when the end-of-data is presented | Releases any resources that are related to its input |
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.)
The compiler does not allow recursive calls 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.
The following table shows how the processing of LIBEXIT changes when there are one or more valid COPY statements that are not nested:
| Action by compiler | Resulting action by exit module |
|---|---|
| Loads the exit module (mod2) during initialization | |
| Calls the exit module with an OPEN operation code (op code) | Prepares the specified library-name for processing. Passes the status of the OPEN request to the compiler. |
| Calls the exit module with a FIND op code if the library-name was successfully opened | Establishes positioning at the requested text-name (or basis-name) in the specified library-name; this place becomes the active copybook. Passes an appropriate return code to the compiler when positioning is complete. |
| Calls the exit module with a FIND op code if the library-name was successfully opened | Reestablishes positioning at the previous active copybook. Passes an appropriate return code to the compiler when positioning is complete. |
| Calls the exit module
with a GET op code.
Verifies that the same record was passed. |
Passes the compiler the same record as was passed previously from this copybook. After verification, passes either the length and address of the record to be copied from the active copybook or the end-of-data indicator. |
| Calls the exit module with a CLOSE op code when the end-of-data is presented | Releases any resources that are related to its input |
The following table shows how the processing of LIBEXIT changes when the compiler encounters a valid nested COPY statement.
| Action by compiler | Resulting action by exit module |
|---|---|
| If the requested library-name from the nested COPY statement was not previously opened, calls the exit module with an OPEN op code | Pushes its control information about the active copybook onto a stack. Completes the requested action (OPEN). The newly requested text-name (or basis-name) becomes the active copybook. |
| Calls the exit module with a FIND op code for the requested new text-name | Pushes its control information about the active copybook onto a stack. Completes the requested action (FIND). The newly requested text-name (or basis-name) becomes the active copybook. |
| Calls the exit module with a GET op code | Passes the compiler either the length and address of the record to be copied from the active copybook or the end-of-data indicator. At end-of-data, pops its control information from the stack. |
The compiler uses a parameter list to communicate with the exit module. The parameter list consists of 10 fullwords that contain addresses, and register 1 contains the address of the parameter list. The return code, data length, and data parameters are placed by the exit module for return to the compiler; and the other items are passed from the compiler to the exit module.
| Offset | Contains address of | Description of item |
|---|---|---|
| 00 | User-exit type | Halfword identifying
which user exit is to perform the operation.
2=LIBEXIT |
| 04 | Operation code | Halfword indicating the
type of operation.
0=OPEN; 1=CLOSE; 2=GET; 4=FIND |
| 08 | Return code | Fullword, placed by the
exit module, indicating the success of the requested operation.
0=Operation was successful; 4=End-of-data; 12=Operation failed |
| 12 | User-exit work area | Four-fullword work area provided by the compiler for use by the user-exit module |
| 16 | Data length | Fullword, placed by the exit module, specifying the length of the record being returned by the GET operation (must be 80) |
| 20 | Data or str2 | Fullword, placed by the
exit module, containing the address of the record in a user-owned
buffer, for the GET operation.
str2 applies only to OPEN. The first halfword (on a halfword boundary) contains the length of the string, followed by the string. |
| 24 | System library-name | Eight-character area containing the library-name from the COPY statement. Processing and conversion rules for a program-name are applied. Padded with blanks if required. Applies to OPEN, CLOSE, and FIND. |
| 28 | System text-name | Eight-character area containing the text-name from the COPY statement (basis-name from BASIS statement). Processing and conversion rules for a program name are applied. Padded with blanks if required. Applies only to FIND. |
| 32 | Library-name | Thirty-character area containing the full library-name from the COPY statement. Padded with blanks if required, and used as-is (not folded to uppercase). Applies to OPEN, CLOSE, and FIND. |
| 36 | Text-name | Thirty-character area containing the full text-name from the COPY statement. Padded with blanks if required, and used as-is (not folded to uppercase). Applies only to FIND. |