Using an existing record format in the file
The Open Query File (OPNQRYF) command does the record selection, and your program processes only the records that meet the selection values. You can use this approach to select a set of records, return records in a different sequence than they are stored, or both.
Assume that you only want your program to process the records in which the Code field is equal to D. You create the program as if there were only records with a D in the Code field. That is, you do not code any selection operations in the program. You then run the OPNQRYF command and specify that only the records with a D in the Code field are to be returned to the program. The following chart is an example of using the OPNQRYF command to select and sequence records:
- 1
- Create the high-level language program to process the database file as you would any normal program using externally described data. Only one format can be used, and it must exist in the file.
- 2
- Run the Override with Database file (OVRDBF) command specifying the file and member to be processed and SHARE(*YES). (If the member is permanently changed to SHARE(*YES) and the first or only member is the one you want to use, this step is not necessary.)
The OVRDBF command can be run after the OPNQRYF command, unless you want to override the file name specified in the OPNQRYF command. In this discussion and in these examples, the OVRDBF command is shown first.
Some restrictions are placed on using the OVRDBF command with the OPNQRYF command. For example, MBR(*ALL) causes an error message and the file is not opened.
- 3
- Run the OPNQRYF command, specifying the database file, member, format names, any selection options, any sequencing options, and the scope of influence for the opened file.
- 4
- Call the high-level language program you created in step 1. Besides using a high-level language, the Copy from Query File (CPYFRMQRYF) command can also be used to process the file created by the OPNQRYF command. Other control language (CL) commands (for example, the Copy File (CPYF) and the Display Physical File Member (DSPPFM) commands) and utilities (for example, Query) do not work on files created with the OPNQRYF command.
- 5
- Close the file that you opened in step 3, unless you want the file to remain open. The Close File (CLOF) command can be used to close the file.
- 6
- Delete the override specified in step 2 with the Delete Override (DLTOVR) command. It might not always be necessary to delete the override, but the command is shown in all the examples for consistency.
Parent topic:
Using Open Query File (OPNQRYF) command
Related concepts
Files shared in a job