Example 4: Selecting records using the Open Query File (OPNQRYF) command
This example shows how to select records using the contains function of the Open Query File (OPNQRYF) command. Assume that you want to process all records in which the Addr field contains the street named BROADWAY. The contains (*CT) function determines if the characters appear anywhere in the named field. You can specify as follows:
OVRDBF FILE(FILEA) SHARE(*YES) OPNQRYF FILE(FILEA) QRYSLT('ADDR *CT "BROADWAY" ') CALL PGM(PGMC) CLOF OPNID(FILEA) DLTOVR FILE(FILEA)In this example, assume that the data is in uppercase in the database record. If the data is in lowercase or mixed case, you can specify a translation function to translate the lowercase or mixed case data to uppercase before the comparison is made. The system-provided table QSYSTRNTBL translates the letters a through z to uppercase. (You can use any translation table to perform the translation.) Therefore, you can specify as follows:OVRDBF FILE(FILEA) SHARE(*YES) OPNQRYF FILE(FILEA) QRYSLT('%XLATE(ADDR QSYSTRNTBL) *CT + "BROADWAY" ') CALL PGM(PGMC) CLOF OPNID(FILEA) DLTOVR FILE(FILEA)When the %XLATE function is used on the QRYSLT statement, the value of the field passed to the high-level language program appears as it is in the database. You can force the field to appear in uppercase using the %XLATE function on the MAPFLD parameter.
Parent topic:
Selecting records using the Open Query File (OPNQRYF) command