Example 8: Selecting records using the Open Query File (OPNQRYF) command

 

This example shows how to select records using the wildcard function of the Open Query File (OPNQRYF) command. Assume that you have a packed decimal Date field in the format MMDDYY and you want to select the records for March 1988. To do this, you can specify:

OVRDBF     FILE(FILEA) SHARE(*YES)
OPNQRYF    FILE(FILEA) +
             QRYSLT('%DIGITS(DATE) *EQ %WLDCRD("03__88")')
CALL       PGM(PGMC)
CLOF       OPNID(FILEA)
DLTOVR     FILE(FILEA)

Note that the only time the MAPFLD parameter is needed to define a database field for the result of the %DIGITS function is when the result needs to be used with a function that only supports a simple field name (not a function or expression) as an argument. The %WLDCRD operation has no such restriction on the operand that appears before the *EQ operator.

Note that although the field in the database is in numeric form, quotation marks surround the literal to make its definition the same as the Char6 field. The wildcard function is not supported for DATE, TIME, or TIMESTAMP data types.

The %WLDCRD function lets you select any records that match your selection values, in which the underline (_) will match any single character value. The two underline characters in Example 8 allow any day in the month of March to be selected. The %WLDCRD function also allows you to name the wild card character (underline is the default). The wild card function supports two different forms:

You can combine the two wildcard functions as shown in this example:
QRYSLT('FLDB *EQ %WLDCRD("ABC_*DEF*") ')

You get a match on ABCxDEF, ABCxxxxxxDEF, ABCxxxDEFxxx, and so on. The underline forces at least one character to appear between the ABC and DEF (for example, ABCDEF would not match). Assume that you have a Name field that contains:

You only gets the first record if you specify:
QRYSLT('NAME *EQ "JOHNS"')
You would not select the other records because a comparison is made with blanks added to the value you specified. The way to select all four names is to specify:
QRYSLT('NAME *EQ %WLDCRD("JOHNS*")')

 

Parent topic:

Selecting records using the Open Query File (OPNQRYF) command

 

Related concepts


Double-byte character set considerations
Control language