• No results found

Close considerations for files shared in a job or an activation group

Here are the considerations for closing a database file that is shared in the same job or activation group.

• The complete processing of a close operation (including releasing file, member, and record locks;

forcing changes to auxiliary storage; and destroying the open data path) is done only when the last program to open the shared open data path closes it.

• If the file was opened with the Open Database File (OPNDBF) or the Open Query File (OPNQRYF) command, use the Close File (CLOF) command to close the file. The Reclaim Resources (RCLRSC)

command can also be used to close a file opened by the OPNQRYF command when one of the following parameters is specified:

– OPNSCOPE(*ACTGRPDFN), and the open is requested from the default activation group.

– TYPE(*NORMAL)

If one of the following parameters is specified, the file remains open even if the Reclaim Resources (RCLRSC) command is run:

– OPNSCOPE(*ACTGRPDFN), and the open is requested from an activation group other than the default.

– OPNSCOPE(*ACTGRP) – OPNSCOPE(*JOB) – TYPE(*PERM)

Example 1: A single set of files with similar processing options You use the same set of files each time you sign on.

A control language (CL) program (PGMA) is used as the first program (to set up the application, including overrides and opening the shared files). PGMA then transfers control to PGMB, which displays the application menu. Assume, in this example, that files A, B, and C are used, and files A and B are to be shared. Files A and B were created with SHARE(*NO); therefore the Override with Database File (OVRDBF) command should precede each of the Open Database File (OPNDBF) commands to specify the

SHARE(*YES) option. File C was created with SHARE(*NO) and File C is not to be shared in this example.

Note: By using the code examples, you agree to the terms of the “Code license and disclaimer information” on page 279.

PGMA: PGM /* PGMA - Initial program */

OVRDBF FILE(A) SHARE(*YES) OVRDBF FILE(B) SHARE(*YES) OPNDBF FILE(A) OPTION(*ALL) ....

OPNDBF FILE(B) OPTION(*INP) ...

TFRCTL PGMB ENDPGM

PGMB: PGM /* PGMB - Menu program */

DCLF FILE(DISPLAY) BEGIN: SNDRCVF RCDFMT(MENU)

IF (&RESPONSE *EQ '1') CALL PGM11 IF (&RESPONSE *EQ '2') CALL PGM12 .

.

IF (&RESPONSE *EQ '90') SIGNOFF GOTO BEGIN

ENDPGM

The files opened in PGMA are either scoped to the job, or PGMA, PGM11, and PGM12 run in the same activation group and the file opens are scoped to that activation group.

In this example, assume that:

• PGM11 opens files A and B. Because these files were opened as shared by the OPNDBF commands in PGMA, the open time is reduced. The close time is also reduced when the shared open data path is closed. The OVRDBF commands remain in effect even though control is transferred (with the Transfer Control (TFRCTL) command in PGMA) to PGMB.

• PGM12 opens files A, B, and C. File A and B are already opened as shared and the open time is reduced.

Because file C is used only in this program, the file is not opened as shared.

In this example, the Close File (CLOF) command is not used because only one set of files is required.

When the operator signs off, the files are automatically closed. It is assumed that PGMA (the initial program) is called only at the start of the job. For more information about how to reclaim resources in the Integrated Language Resources, see the ILE Concepts book.

Note: The display file (DISPLAY) in PGMB can also be specified as a shared file, which can improve the performance for opening the display file in any programs that use it later.

In Example 1, the OPNDBF commands are placed in a separate program (PGMA) so the other processing programs in the job run as efficiently as possible. That is, the important files used by the other programs in the job are opened in PGMA. After the files are opened by PGMA, the main processing programs (PGMB, PGM11, and PGM12) can share the files; therefore, their open and close requests will process faster. In addition, by placing the open commands (OPNDBF) in PGMA rather than in PGMB, the amount of main storage used for PGMB is reduced.

Any overrides and opens can be specified in the initial program (PGMA); then, that program can be removed from the job (for example, by transferring out of it). However, the open data paths that the program created when it opened the files remain in existence and can be used by other programs in the job.

Note: Overrides must be specified before the file is opened. Some of the parameters on the OVRDBF command also exist on the OPNDBF command. If conflicts arise, the OVRDBF value is used.

Related concepts ILE Concepts PDF

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:

Note: By using the code examples, you agree to the terms of the “Code license and disclaimer information” on page 279.

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.

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:

• 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).

The following example shows the RCLRSC command used to close files:

. .

IF (&RESPONSE *EQ '1') DO CALL ACCRECV

RCLRSC ENDDO

IF (&RESPONSE *EQ '2') DO CALL ACCPAY

RCLRSC ENDDO . .

Example 3: A single set of files with different processing options

You use the same set of files for programs that need read-only file processing and for programs that need some or all of the options (input, update, add, and delete).

The same methods apply if a file is to be processed with certain command parameters in some programs and not in others (for example, sometimes the commit option should be used).

A single Open Database File (OPNDBF) command can be used to specify OPTION(*ALL) and the open data path would be opened shared (if, for example, a previous Override with Database File (OVRDBF)

command was used to specify SHARE(*YES)). Each program can then open a subset of the options. The program requests the type of open depending on the specifications in the program. In some cases this does not require any more considerations because a program specifying an open for input only would operate similarly as if it had not done a shared open (for example, no additional record locking occurs when a record is read).

However, some options specified on the OPNDBF command can affect how the program operates. For example, SEQONLY(*NO) is specified on the open command for a file in the program. An error would occur if the OPNDBF command used SEQONLY(*YES) and a program attempted an operation that was not valid with sequential-only processing.

The ACCPTH parameter must also be consistent with the way programs will use the access path (arrival or keyed).

If COMMIT(*YES) is specified on the OPNDBF command and the Start Commitment Control (STRCMTCTL) command specifies LCKLVL(*ALL) or LCKLVL(*CS), any read operation of a record locks that record (per

commitment control record locking rules). This can cause records to be locked unexpectedly and cause errors in the program.

Two OPNDBF commands can be used for the same data (for example, one with OPTION(*ALL) and the other specifying OPTION(*INP)). The second use must be a logical file pointing to the same physical file(s). This logical file can then be opened as SHARE(*YES) and multiple uses made of it during the same job.