Example 6: Select records using the Open Query File (OPNQRYF) command

This example shows how to use the Open Query File (OPNQRYF) command many times in a program.

You can use the OPNQRYF command more than once in a high-level language program. For example, assume you want to prompt the user for some selection values, then display one or more pages of records. At the end of the first request for records, the user might want to specify other selection values and display those records. This can be done by follow these steps:

  1. Before calling the high-level language program, use an Override with Database File (OVRDBF) command to specify SHARE(*YES).
  2. In the high-level language program, prompt the user for the selection values.
  3. Pass the selection values to a control language (CL) program that issues the OPNQRYF command (or run the command with a call to program QCMDEXC). The file must be closed before your program processes the OPNQRYF command. You normally use the Close File (CLOF) command and monitor for the file not being open.
  4. Return to the high-level language program.
  5. Open the file in the high-level language program.
  6. Process the records.
  7. Close the file in the program.
  8. Return to step 2.
When the program completes, run the CLOF command or the Reclaim Resources (RCLRSC) command to close the file, then delete the OVRDBF command specified in step 1.
Note: An override command in a called CL program does not affect the open in the main program. All overrides are implicitly deleted when the program is ended. (However, you can use a call to program QCMDEXC from your high-level language program to specify an override, if needed.)