This example shows how to select records with a specific value using the Open Query File (OPNQRYF) command.
OVRDBF FILE(FILEA) SHARE(*YES) OPNQRYF FILE(FILEA) QRYSLT('CODE *EQ "D" ') CALL PGM(PGMB) CLOF OPNID(FILEA) DLTOVR FILE(FILEA)
OPNQRYF FILE(FILEA) QRYSLT('AMT *GT 1000.00')
Numeric constants are not enclosed by quotation marks.
OPNQRYF FILE(FILEA) QRYSLT('"' *CAT &CHAR *CAT '" *EQ FIELDA')or, in reverse order:
OPNQRYF FILE(FILEA) QRYSLT('FIELDA *EQ "' *CAT &CHAR *CAT '"')
OPNQRYF FILE(FILEA) QRYSLT(&CHARNUM *CAT ' *EQ NUM')or, in reverse order:
OPNQRYF FILE(FILEA) QRYSLT('NUM *EQ ' *CAT &CHARNUM);
When comparing two fields or constants, the data types must be compatible. The following table describes the valid comparisons.
Any numeric | Character | Date1 | Time1 | Timestamp1 | |
---|---|---|---|---|---|
Any numeric | Valid | Not valid | Not valid | Not valid | Not valid |
Character | Not valid | Valid | Valid2 | Valid2 | Valid2 |
Date1 | Not valid | Valid2 | Valid | Not valid | Not valid |
Time1 | Not valid | Valid2 | Not valid | Valid | Not valid |
Timestamp1 | Not valid | Valid2 | Not valid | Not valid | Valid |
1 Date, time, and timestamp data types can be represented by fields and expressions, but not constants; however, character constants can represent date, time, or timestamp values.
2 The character field or constant must represent a valid date value if compared to a date data type, a valid time value if compared to a time data type, or a valid timestamp value if compared to a timestamp data type.
The performance of record selection can be greatly enhanced if a file on the system uses the field being selected in a keyed sequence access path. This allows the system to quickly access only the records that meet the selection values. If no such access path exists, the system must read every record to determine if it meets the selection values.
Even if an access path exists on the field you want to select from, the system might not use the access path. For example, if it is faster for the system to process the data in arrival sequence, it will do so.