Initializing the exit
Initializing the exit is trivial for a High Level Language (HLL) like COBOL or PL/I. Language Environment® (LE) obtains storage for HLLs. In the case of the sample exit, before COBOL starts, LE obtains the required COBOL working storage. Whenever the COBOL program is called, LE ensures it has access to its working storage. LE also maintains the data in working storage across calls.
If the user exit is written in HLASM, however, initializing the exit is more complex. You can use the INIT-RAM and TERM-RAM calls to get and release storage needed by the exit. The exit can set the second argument in every call to the exit, the RAM-WORK-AREA-PTR, at any time. File Manager preserves and passes this value with every call to the exit. This provides a way for the exit to gain addressability to storage on every call. The exit should release all storage when it receives a call to TERM-RAM.
The sample COBOL exit code does not use the RAM-WORK-AREA-PTR, because, as mentioned above, LE provides an alternative to this mechanism for HLLs.
The code in INIT-RAM in the sample exit simply sets the tracing level from the caller and sets up the callback logging function address.
The arguments are:
Parm0 = OpCode = InitializeRAM
Parm1 = RAM-WORK-AREA-PTR
Parm2 = (Reserved)
Parm3 = TRACELVL (integer value from 0 to 3)
Parm4 = Trace callback function address
The sample exit has two statements, PERFORM CLOSE-AND-FREE-DIRFILE and PERFORM CLOSE-AND-FREE-MEMFILE, that you may need to change to free your own resources. This is done to ensure that even if a previous instance of the exit abended prior to freeing resources, the resources will be freed.