Typical errors when using the Open Query File (OPNQRYF) command
You must specify several functions correctly for the Open Query File (OPNQRYF) command and your program to get correct results.
The Display Job (DSPJOB) command is your most useful tool if problems occur. This command supports both the open files option and the file overrides option. You can look at both options if you are having problems. Listed here are the most common problems you might encounter when using the OPNQRYF command and the ways to correct them:
- Shared open data path (ODP). The OPNQRYF command operates through a shared ODP. In order for the file to process correctly, the member must be opened for a shared ODP. If you are having problems, use the open files option on the DSPJOB command to determine if the member is opened and has a shared ODP. There are normally two reasons that the file is not open:
- The member to be processed must be SHARE(*YES). Either use an Override with Database File (OVRDBF) command or permanently change the member.
- The file is closed. You have run the OPNQRYF command with the OPNSCOPE(*ACTGRPDFN) or TYPE(*NORMAL) parameter option from a program that was running in the default activation group at a higher level in the call stack than the program that is getting an error message or that is running the Reclaim Resources (RCLRSC) command. This closes the open query file because it was opened from a program at a higher level in the call stack than the program that ran the RCLRSC command. If the open query file was closed, run the OPNQRYF command again. Note that when using the OPNQRYF command with the TYPE(*NORMAL) parameter option on releases prior to Version 2 Release 3, the open query file is closed even if it was opened from the same program that reclaims the resources.
- Level check. Level checking is normally used because it ensures that your program is running against the same record format that the program was compiled with. If you are experiencing level check problems, it is normally because of one of the following reasons:
- The record format was changed since the program was created. Creating the program again should correct the problem.
- An override is directing the program to an incorrect file. Use the file overrides option on the DSPJOB command to ensure that the overrides are correctly specified.
- The FORMAT parameter is needed but is either not specified or incorrectly specified. When a file is processed with the FORMAT parameter, ensure:
- The OVRDBF command, used with the TOFILE parameter, describes the first file on the FILE parameter of the OPNQRYF command.
- The FORMAT parameter identifies the file that contains the format used to create the program.
- The FORMAT parameter is used to process a format from a different file (for example, for group processing), but SHARE(*YES) was not requested on the OVRDBF command.
- The file to be processed is at end of file. The normal use of the OPNQRYF command is to process a file sequentially where you can only process the file once. At that point, the position of the file is at the end of the file and you will not receive any records if you attempt to process it again. To process the file again from the start, either run the OPNQRYF command again or reposition the file before processing. You can reposition the file by using the Position Database File (POSDBF) command, or through a high-level language program statement.
- No records exist. This can be caused when you use the FORMAT keyword, but do not specify the OVRDBF command.
- Syntax errors. The system found an error in the specification of the OPNQRYF command.
- Operation not valid. The definition of the query does not include the KEYFLD parameter, but the high-level language program attempts to read the query file using a key field.
- Get option not valid. The high-level language program attempted to read a record or set a record position before the current record position, and the query file used either the group by option, the unique key option, or the distinct option on the SQL statement.
Parent topic:
Using Open Query File (OPNQRYF) command