HPlogo SORT-MERGE/XL General Users Guide: HP 3000 MPE/iX Computer Systems > Chapter 3 Using SORT/XL Interactively

Multiple Key Alphabetical Sorting

» 

Technical documentation

Complete book in PDF
» Feedback

 » Table of Contents

 » Glossary

 » Index

You can designate multiple key data items to break sorting ties. This prevents the situation described in the "Single Key Alphabetical Sorting" section above, where there were three ANDERSON entries in the file. Issue the following commands to designate multiple keys for the file EMPLOYEE. Only the three lines of the file listing the ANDERSON entries are shown:

     :SORT 



     HP32214A.01.00  SORT/3000 WED, JUN  3, 1987,  8:28 AM 

     © HEWLETT-PACKARD CO. 1986 



     >INPUT EMPLOYEE  

     >OUTPUT COMPANY 

     >KEY 1, 11   

     >KEY 12, 11   

     >END   

     PURGE OLD OUTPUT FILE COMPANY.GROUP.ACCOUNT ? Y   



        <<The SORT Statistics Appear Here>> 



     :EDITOR   



     HP32201A.07.17 EDIT/3000 WED, JUN  3, 1987,  8:29 AM 

     © HEWLETT-PACKARD CO. 1985 

     /TEXT COMPANY   

     FILE UNNUMBERED 

     /LIST 1/3   

                   1         2         3         4 

          123456789012345678901234567890123456789012345 



     1    ANDERSON   CHARLES    SALES REP          3456 

     2    ANDERSON   CHARLES    PRESIDENT          0247 

     3    ANDERSON   MARY       ACCOUNTANT         6345 

The two entries for CHARLES ANDERSON now appear before MARY ANDERSON in the list. However, for the sort to be completely alphabetized the job title also needs to be considered. To accomplish this you would designate three key data items with the >KEY command.

To designate three key data items for last name, first name, and job title, enter the following sequence of commands:

     :SORT   



     HP32214A.01.00  SORT/3000 WED, JUN  3, 1987,  8:30 AM 

     © HEWLETT-PACKARD CO. 1986 



     >INPUT EMPLOYEE     

     >OUTPUT COMPANY   

     >KEY 1, 11; 12, 11; 23, 19   

     >END   

     PURGE OLD OUTPUT FILE COMPANY.GROUP.ACCOUNT ? Y    



        <<The SORT Statistics Appear Here>> 



     :EDITOR   



     HP32201A.07.17 EDIT/3000 WED, JUN  3, 1987,  8:31 AM 

     © HEWLETT-PACKARD CO. 1985 

     /TEXT COMPANY   

     FILE UNNUMBERED 

     /LIST 1/3    

                   1         2         3         4 

          123456789012345678901234567890123456789012345 



     1    ANDERSON   CHARLES    PRESIDENT          0247 

     2    ANDERSON   CHARLES    SALES REP          3456 

     3    ANDERSON   MARY       ACCOUNTANT         6345 

The three ANDERSON entries are now correctly alphabetized by last name, first name, and job title. Notice in the last two examples that it is acceptable to enter multiple key data items with the >KEY command either one to a line or all on one line.

In the above example, after you entered the >END command, the system displayed the message:

        PURGE OLD OUTPUT FILE COMPANY.GROUP.ACCOUNT ? Y   

This message tells you that a file named COMPANY already exists in your group and account, and asks if you want the old version purged. If you reply YES, the old version of COMPANY is purged and a new version containing the information from this sort is created. If you reply NO you are prompted for a new file name. You then enter a new, unique file name and you have two files; the original file named COMPANY and the newly created file.

Feedback to webmaster