Example 10: Select records using the Open Query File (OPNQRYF) command

This example shows the use of the coded character set identifiers (CCSIDs) when you run the Open Query File (OPNQRYF) command to select records.

Each character and DBCS field in all database files is tagged with a CCSID. This CCSID allows you to further define the data stored in the file so that any comparison, join, or display of the fields is performed in a meaningful way. For example, if you compare FIELD1 in FILE1 where FIELD1 has a CCSID of 37 (USA) to FIELD2 in FILE2 where FILED2 has a CCSID of 273 (Austria, Germany), appropriate mapping occurs to make the comparison meaningful.
OPNQRYF FILE(FILEA FILEB) FORMAT(RESULTF) +
        JFLD((FILEA/NAME FILEB/CUSTOMER))

If field NAME has a CCSID of 37 and field CUSTOMER has a CCSID of 273, the mapping of either NAME or CUSTOMER is performed during processing of the OPNQRYF command so that the join of the two fields provides a meaningful result.

Normally, constants defined in the MAPFLD, QRYSLT, and GRPSLT parameters are tagged with the CCSID defined to the current job. This suggests that when two users with different job CCSIDs run the same OPNQRYF command (or a program containing an OPNQRYF command) and the OPNQRYF command has constants defined in it, the users can get different results because the CCSID tagged to the constants might cause the constants to be treated differently.

You can tag a constant with a specific CCSID by using the MAPFLD parameter. By specifying a MAPFLD whose definition consists only of a constant and then specifying a CCSID for the MAPFLD, the constant becomes tagged with the CCSID specified in the MAPFLD parameter. For example:
OPNQRYF FILE(FILEA) FORMAT(RESULTF) QRYSLT('NAME *EQ MAP1') +
        MAPFLD((MAP1 '"Smith"' *CHAR 5 *N 37))
The constant "Smith" is tagged with the CCSID 37 regardless of the job CCSID of the user issuing the OPNQRYF command. In this example, all users get the same result records (although the result records would be mapped to the user's job CCSID). Conversely, if the query is specified as:
OPNQRYF FILE(FILEA) FORMAT(RESULTF) QRYSLT('NAME *EQ "Smith"')
The results of the query might differ, depending on the job CCSID of the user issuing the OPNQRYF command.
Related concepts
i5/OS globalization