Example 2: Multiple sets of files with similar processing options
You use a different set of files for each program. You normally work with one program for a considerable length of time before selecting a new program.
Assume that a menu requests the operator to specify the application program (for example, accounts receivable or accounts payable) that uses the Open Database File (OPNDBF) command to open the required files. When the application is ended, the Close File (CLOF) command closes the files. The CLOF command is used to help reduce the amount of main storage needed by the job. An example of the accounts receivable programs follows:
By using the code examples, you agree to the terms of the Code license and disclaimer information.
PGMC: PGM /* PGMC PROGRAM */ DCLF FILE(DISPLAY) BEGIN: SNDRCVF RCDFMT(TOPMENU) IF (&RESPONSE *EQ '1') CALL ACCRECV IF (&RESPONSE *EQ '2') CALL ACCPAY . . IF (&RESPONSE *EQ '90') SIGNOFF GOTO BEGIN ENDPGM ACCREC: PGM /* ACCREC PROGRAM */ DCLF FILE(DISPLAY) OVRDBF FILE(A) SHARE(*YES) OVRDBF FILE(B) SHARE(*YES) OPNDBF FILE(A) OPTION(*ALL) .... OPNDBF FILE(B) OPTIONS(*INP) ... BEGIN: SNDRCVF RCDFMT(ACCRMENU) IF (&RESPONSE *EQ '1') CALL PGM21 IF (&RESPONSE *EQ '2') CALL PGM22 . . IF (&RESPONSE *EQ '88') DO /* Return */ CLOF FILE(A) CLOF FILE(B) RETURN ENDDO GOTO BEGIN ENDPGMThe program for the accounts payable menu would be similar, but with a different set of OPNDBF and CLOF commands.
For this example, files A and B were created with SHARE(*NO). Therefore, an OVRDBF command must precede the OPNDBF command. As in Example 1, the amount of main storage used by each job can be reduced by placing the OPNDBF commands in a separate program and calling it. A separate program can also be created for the CLOF commands. The OPNDBF commands can be placed in an application setup program that is called from the menu, which transfers control to the specific application program menu (any overrides specified in this setup program are kept). However, calling separate programs for these functions also uses system resources and, depending on the frequency with which the different menus are used, it might be better to include the OPNDBF and CLOF commands in each application program menu as shown in this example. Another choice is to use the Reclaim Resources (RCLRSC) command in PGMC (the setup program) instead of using the CLOF command. The RCLRSC command closes any files and frees any leftover storage associated with any files and programs that were called and have since returned to the calling program. However, RCLRSC does not close files that are opened with the following parameters specified on the OPNDBF or Open Query File (OPNQRYF) command:
The following example shows the RCLRSC command used to close files:
- OPNSCOPE(*ACTGRPDFN), and the open is requested from some activation group other than the default.
- OPNSCOPE(*ACTGRP) reclaims if the RCLRSC command is from an activation group with an activation group number that is lower than the activation group number of the open.
- OPNSCOPE(*JOB).
- TYPE(*PERM).
. . IF (&RESPONSE *EQ '1') DO CALL ACCRECV RCLRSC ENDDO IF (&RESPONSE *EQ '2') DO CALL ACCPAY RCLRSC ENDDO . .
Parent topic:
Close considerations for files shared in a job or an activation group