OVRDBF can be used to redirect the file selection to a file of another name or in a specific library.
OPNQRYF provides a method to select records, join files, etc. It is a lot like SQL select.
We would usually see the two together – the override requires the share(*yes) so called programs get access to the query file. Here is a CL
OVRDBF file(xxxx) share(*yes)
OPNQRYF file(xxxx) QRYSLT( ‘STFLD = “MO”‘))
This query would limit select records to those with MO in the STFLD.
It would appear to program rpg1 that the file xxxx only contained records for ‘MO’
This can provide flexibility to a rather simple RPG program.
The QrySlt can be a *char variable which you can build based on your current need.
There is much more to these commands.
Regarding OPNQRYF: It uses the original, or classic query engine (CQE) which IBM is no longer enhancing for performance and additional functionality, so it is better to use embedded SQL.
SQL statements will generally use the newer engine, SQE, except in certain circumstances. The goal is to have the system use the SQE, which should perform better. One of the ways to facilitate this is to query just the physical file or table in an SQL statement, and let the system figure out which index it finds best to use. Using a logical file will result in the system using the CQE instead, which is less desirable from a performance perspective.
Also, see these for some detailed info: