In this example, different files are used for each application. The user normally works with one application for a considerable length of time before selecting a new application.
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.
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 ENDPGM
The 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.
. . IF (&RESPONSE *EQ '1') DO CALL ACCRECV RCLRSC ENDDO IF (&RESPONSE *EQ '2') DO CALL ACCPAY RCLRSC ENDDO . .