Compaq AAQ2G1FTK Marine Radio User Manual


 
9
Using the SORT and MERGE Statements
This chapter includes the following information about using the SORT and
MERGE statements to sort and merge records for sequential, line sequential,
relative, and indexed files:
Sorting data with the SORT statement (Section 9.1)
Merging data with the MERGE statement (Section 9.2)
Sample programs using the SORT and MERGE statements (Section 9.3)
9.1 Sorting Data with the SORT Statement
The SORT statement provides a wide range of sorting capabilities and options.
To establish a SORT routine, you do the following:
1. Declare the sort file with an Environment Division SELECT statement.
2. Use a Data Division Sort Description (SD) entry to define the sort file’s
characteristics.
3. Use a Procedure Division SORT statement.
The following program segments demonstrate SORT program coding:
SELECT Statement (Environment Division)
SELECT SORT-FILE ASSIGN TO "SRTFIL"
An SD File Description Entry (Data Division)
SD SORT-FILE.
01 SORT-RECORD.
05 SORT-KEY1 PIC X(5).
05 SOME-DATA PIC X(25).
05 SORT-KEY2 PIC XX.
Note
You can place the sort file anywhere in the FILE SECTION, but you must
use a Sort Description (SD) level indicator, not a File Description (FD)
level indicator. Also, you cannot use the SD file for any other purpose in
the COBOL program.
SORT Statement (Procedure Division)
SORT SORT-FILE
ASCENDING KEY S-NAME
USING NAME-FILE
GIVING NEW-FILE.
The SORT statement names a sort file, sort keys, an input file, and an output file.
An explanation of sort keys follows.
Using the SORT and MERGE Statements 91