Content-length: 4038 Content-Type: text/html; charset=UTF-8
Midrange Information, Tips and Technique
sby Brian Coy
Use %WLDCRD to Match the End of a Field:
The Open Query File (OPNQRYF) command’s wild card (%WLDCRD) function is powerful. When combined with the %STRIP function, it’s even more effective.
Suppose the format of a general ledger account number depends on the type of account it is. An asset account may look like 1-3, while an expense account may look like 51-735-5. How would you find transactions for all accounts ending in -5?
The following code wouldn’t work because the -5 characters would have to occupy the last 2 bytes of the general ledger account number field.
OPNQRYF FILE((GLENTRY)) QRYSLT(‘ACCT *EQ %WLDCRD("*-5")’)
Instead, you would have to do this:
OPNQRYF FILE((GLENTRY)) QRYSLT(‘%STRIP(ACCT) *EQ %WLDCRD("*-5")’)
The %STRIP function removes leading and trailing blanks from the account number before the comparison takes place. In this case, the -5 characters would have to be the last nonblank characters in the account number, but they would not have to be in the last two positions of the field.