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 allow any day in the month of March to be selected.
OPNQRYF FILE(FILEA) +
QRYSLT('%DIGITS(DATE) *EQ %WLDCRD("03__2005")')
The wildcard function is not supported for DATE, TIME, or TIMESTAMP data types. The %WLDCRD function also allows you to name the wild card character (underline is the default).
The wild card function supports two different forms:
• A fixed-position wild card as shown in the previous example in which the underline matches any single character as in the following example:
QRYSLT('FLDA *EQ %WLDCRD("A_C")')
This compares successfully to ABC, ACC, ADC, AxC, and so on. In this example, the field being analyzed only compares correctly if it is exactly 3 characters in length. If the field is longer than 3 characters, you also need the second form of wild card support.
• A variable-position wild card will match any zero or more characters. The Open Query File (OPNQRYF) command uses an asterisk (*) for this type of wild card variable character or you can specify your own character. An asterisk is used in the following example:
QRYSLT('FLDB *EQ %WLDCRD("A*C*") ')
This compares successfully to AC, ABC, AxC, ABCD, AxxxxxxxC, and so on. The asterisk causes the command to ignore any intervening characters if they exist. Notice that in this example the asterisk is specified both before and after the character or characters that can appear later in the field. If the asterisk were omitted from the end of the search argument, it causes a selection only if the field ends with the character C.
You must specify an asterisk at the start of the wild card string if you want to select records where the remainder of the pattern starts anywhere in the field. Similarly, the pattern string must end with an asterisk if you want to select records where the remainder of the pattern ends anywhere in the field.
For example, you can specify:
QRYSLT('FLDB *EQ %WLDCRD("*ABC*DEF*") ')
You get a match on ABCDEF, ABCxDEF, ABCxDEFx, ABCxxxxxxDEF, ABCxxxDEFxxx, xABCDEF, xABCxDEFx, and so on.
You can combine the two wildcard functions as in the following 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).
Monday, September 10, 2007
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment