Other methods for indexing mixed case fields

The following are several ways to index files in different sequences, in particular, to mix uppercase and lowercase so they will sort together.

In the recent tip by Tim Granatir, he discussed a way to do this for logical files by adding a field to the logical file, and then using the RENAME and TRNTBL keywords to sort both cases together.

Below are other (easier) ways to do this, especially if there are multiple key fields, and they work for BOTH physical and logical files.

The first thing to be aware of are the different sort sequence tables. Use the command WRKSEQ *ALL to see a list of tables in your job library list. Assuming you have the authority, you will see system tables including QSYSTRNTBL, QCASE256B, etc., which convert lower case to upper case, plus tables for languages other than English. In case one of the existing system tables won't do what you need, you can also create you own table, or copy a system table and modify it.

Method 1
In the CRTPF, CHGPF, and CTRLF, the parameter SRTSEQ can be used to specify a sort sequence table. For example, you could enter SRTSEQ(QSYSTRNTBL). Even easier, if you do not need to use a special table of your own, you can use STRSEQ(*LANGIDSHR) or STRSEQ(*LANGIDUNQ) to get the results in the language used on your system.

There is a distinction between the two options. *LANGIDSHR is similar to QSYSTRNTBL, etc., mentioned above, in that lowercase letters are treated the exactly the same as uppercase, for sorting purposes (i.e., they share the same sort sequence).

So you might see a file sorted like this, where upper and lower case letters are mixed for the same letter:
bob
Bob
bob
Bob
BOB
bob
dick
Dick
dick
Dick
DICK
dick
harry
Harry
harry
Harry
HARRY
Harry

*LANGIDUNQ also sorts alphabetically, but for each letter, it sorts lower case before uppercase (i.e., they have unique sort sequences). So the same data as in the above example would sort like this:
bob
bob
bob
Bob
Bob
BOB
dick
dick
dick
Dick
Dick
DICK
harry
harry
harry
Harry
Harry
HARRY

Method 2
The SRTSEQ parameter technique, above, applies to all key fields in the file. If you need to apply the alternate sort sequence to selected key fields only, or if you want to store the sort sequence information in the DDS, then use the file-level keyword ALTSEQ to specify an alternate sort sequence table. You cannot use this technique if the file has packed decimal, binary, or floating-point key fields. This technique also causes zoned key fields to default to unsigned sequence, although this can be overridden for individual key fields.

If you want this to apply to all key fields, then you are done. If you need to have some key fields use the normal EBCDIC sort sequence, you can override the alternate sort sequence table at the individual key field level with the keywords NOALTSEQ (for character key fields) or SIGNED (for zoned key fields). See the DDS manual for more information.

For example

A*                                     ALTSEQ(QSYSTRNTBL) 
A          R RSORTTST                                     
A            KEYFIELD1     10                             
A            KEYFIELD2     10                             
A            KEYFIELD3      7S 2                          
A            KEYFIELD4     10                             
 * Key fields                                             
A          K KEYFIELD1                                    
A          K KEYFIELD2                 NOALTSEQ           
A          K KEYFIELD3                 SIGNED             
A          K KEYFIELD4 


This was first published in February 2001
This Content Component encountered an error

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchEnterpriseLinux

SearchDataCenter

Close