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

This example shows the use of sort sequence and language identifier when you run the Open Query File (OPNQRYF) command to select records.

To see how to use a sort sequence, run the examples in this topic against the STAFF file shown in Table 1.

Table 1. The STAFF file
ID NAME DEPT JOB YEARS SALARY COMM
10 Sanders 20 Mgr 7 18357.50 0
20 Pernal 20 Sales 8 18171.25 612.45
30 Merenghi 38 MGR 5 17506.75 0
40 OBrien 38 Sales 6 18006.00 846.55
50 Hanes 15 Mgr 10 20659.80 0
60 Quigley 38 SALES 00 16808.30 650.25
70 Rothman 15 Sales 7 16502.83 1152.00
80 James 20 Clerk 0 13504.60 128.20
90 Koonitz 42 sales 6 18001.75 1386.70
100 Plotz 42 mgr 6 18352.80 0
In the examples, the results are shown for a particular statement using each of the following sort sequences:
  • *HEX sort sequence.
  • Shared-weight sort sequence for language identifier ENU.
  • Unique-weight sort sequence for language identifier ENU.
Note: ENU is chosen as a language identifier by specifying either SRTSEQ(*LANGIDUNQ) or SRTSEQ(*LANGIDSHR), and LANGID(ENU) in the OPNQRYF command.
The following command selects records with the value MGR in the JOB field:
OPNQRYF FILE(STAFF) QRYSLT('JOB *EQ "MGR"')
Table 2 shows the record selection with the *HEX sort sequence. The records that match the record selection criteria for the JOB field are selected exactly as specified in the QRYSLT statement; only the uppercase MGR is selected.
Table 2. Use the *HEX sort sequence. OPNQRYF FILE(STAFF) QRYSLT('JOB *EQ "MGR"') SRTSEQ(*HEX)
ID NAME DEPT JOB YEARS SALARY COMM
30 Merenghi 38 MGR 5 17506.75 0

Table 3 shows the record selection with the shared-weight sort sequence. The records that match the record selection criteria for the JOB field are selected by treating uppercase and lowercase letters the same. With this sort sequence, mgr, Mgr, and MGR values are selected.

Table 3. Use the shared-weight sort sequence. OPNQRYF FILE(STAFF) QRYSLT('JOB *EQ "MGR"') SRTSEQ(LANGIDSHR) LANGID(ENU)
ID NAME DEPT JOB YEARS SALARY COMM
10 Sanders 20 Mgr 7 18357.50 0
30 Merenghi 38 MGR 5 17506.75 0
50 Hanes 15 Mgr 10 20659.80 0
100 Plotz 42 mgr 6 18352.80 0

Table 4 shows the record selection with the unique-weight sort sequence. The records that match the record selection criteria for the JOB field are selected by treating uppercase and lowercase letters as unique. With this sort sequence, the mgr, Mgr, and MGR values are all different. The MGR value is selected.

Table 4. Use the unique-weight sort sequence. OPNQRYF FILE(STAFF) QRYSLT('JOB *EQ "MGR"') SRTSEQ(LANGIDUNQ) LANGID(ENU)
ID NAME DEPT JOB YEARS SALARY COMM
30 Merenghi 38 MGR 5 17506.75 0