This example shows how to map fields for packed numeric data fields using the Open Query File (OPNQRYF) command.
Assume that you have a packed decimal Date field in the format MMDDYY and you want to select all the records for the year 1988. You cannot select records directly from a portion of a packed decimal field, but you can use the MAPFLD parameter on the OPNQRYF command to create a new field that you can then use for selecting part of the field.
The format of each mapped field definition is:
(result field 'expression' attributes)
OVRDBF FILE(FILEA) SHARE(*YES) OPNQRYF FILE(FILEA) QRYSLT('YEAR *EQ "88" ') + MAPFLD((CHAR6 '%DIGITS(DATE)') + (YEAR '%SST(CHAR6 5 2)' *CHAR 2)) CALL PGM(PGMC) CLOF OPNID(FILEA) DLTOVR FILE(FILEA)
OPNQRYF FILE(FILEA) + QRYSLT ('YEAR *EQ 88') + MAPFLD((YEAR '%YEAR(DATE)'))
The first mapped field definition specifies that the Char6 field be created from the packed decimal Date field. The %DIGITS function converts from packed decimal to character and ignores any decimal definitions (that is, 1234.56 is converted to '123456'). Because no definition of the Char6 field is specified, the system assigns a length of 6. The second mapped field defines the Year field as type *CHAR (character) and length 2. The expression uses the substring function to map the last 2 characters of the Char6 field into the Year field.
OPNQRYF FILE(FILEA) + QRYSLT('%SST(CHAR6 5 2) *EQ "88" ') + MAPFLD((CHAR6 '%DIGITS(DATE)'))