Example 2: Control how the system runs the Open Query File command

This example shows how to optimize to minimize the number of records read.

Assume that you have multiple programs that will access the same file which is built by the Open Query File (OPNQRYF) command. In this case, you will want to optimize the performance so that the application programs read only the data they are interested in. This means that you want OPNQRYF to perform the selection as efficiently as possible. You can specify:
OVRDBF   FILE(FILEA) SHARE(*YES)
OPNQRYF  FILE(FILEA) QRYSLT('CODE *EQ "B"') +
         KEYFLD(CUST) OPTIMIZE(*MINWAIT)
CALL     PGM(PGMA)
POSDBF   OPNID(FILEA) POSITION(*START)
CALL     PGM(PGMB)
CLOF     OPNID(FILEA)
DLTOVR   FILE(FILEA)