You probably know that you can use the Reclaim Resource (RCLRSC) command to clean up open files and reclaim program storage. The default value for the Program Level (LVL) parameter is an asterisk (*), which says to close all open files and programs, including the calling program, once the called programs have finished running.
Did you know that you can also specify *CALLER in this parameter? Use this parameter value when you want to leave programs and files open in the calling program while still closing programs and files that were called by the original program. Let's see what this means by way of an example.
PGMSTART (Figure 11) opens FILE1 and calls PGMA (Figure 12), which opens FILE2. The program then exits with the file still open, using the RETRN op code. PGMSTART then calls PGMB (Figure 13), which opens FILE3 and then exits with the file still open, using the RETRN op code. PGMSTART then calls RCLPGMC (Figure 14), a CL program that executes the RCLRSC command, using *CALLER in the LVL parameter. When control returns to PGMSTART, it stops execution, ending with the RETRN op code. When PGMSTART finishes, only FILE1 is left open. The files in PGMA and PGMB are closed, and all storage allocated for them is reclaimed. Another operation could execute PGMSTART again and would be able to use the open access path to FILE1, and all variables would still be in their previous state.
- Shannon O'Donnell
Editor's Note: The help text for the RCLRSC command provides additional information you should know about. For instance, RCLRSC command is not needed to reclaim the resources of all CL programs that end (return) normally, of RPG programs that have the last record (LR) indicator set on, or of any COBOL programs. RCLRSC should not be used if it might be processed while any COBOL program is still active in the application; instead, use the COBOL CANCEL statement.
Other important facts: RCLRSC should not specify LVL(*CALLER) if it is used in a CL
program that also uses the Send File (SNDF), Receive File (RCVF), or Send Receive File (SNDRCVF) commands; using *CALLER in such a program causes unpredictable results when the other commands are used after the program runs. Unpredictable results can also occur if RCLRSC is executed from a command line with the LVL(*CALLER) parameter.
Figure 11: RPG III program PGMSTART
FFILE1 IF E K DISK *
C READ FILE1 99
C *IN99 IFEQ *OFF
C CALL 'PGMA'
C CALL 'PGMB'
C CALL 'RCLPGMC'
C ENDIF
C RETRN FFILE2 IF E K DISK *
C READ FILE2 99
C RETRN FFILE3 IF E K DISK *
C READ FILE3 99
C RETRN
Figure 14: CL program RCLPGMC
PGM
RCLRSC LVL(*CALLER)
ENDPGM
LATEST COMMENTS
MC Press Online