Example 6: Dynamically selecting records
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 that you want to prompt the user for some selection values and 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. You can do this by following these steps:
- Before calling the high-level language program, use an Override with Database File (OVRDBF) command to specify SHARE(*YES).
- In the high-level language program, prompt the user for the selection values.
- 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.
- Return to the high-level language program.
- Open the file in the high-level language program.
- Process the records.
- Close the file in the program.
- 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.)