beautypg.com

Compaq COBOL AAQ2G1FTK User Manual

Page 286

background image

Using the SORT and MERGE Statements
9.1 Sorting Data with the SORT Statement

Example 9–4 (Cont.) Using Two Sort Files

01

SORT-REC-2.
03

FILLER

PIC X(20).

03

S2-KEY-1

PIC X(10).

03

FILLER

PIC X(10).

03

S2-KEY-2

PIC X(10).

03

FILLER

PIC X(50).

.
.
.

PROCEDURE DIVISION.
000-SORT SECTION.
010-DO-FIRST-SORT.

SORT SORT-FILE1 ON ASCENDING KEY

S1-KEY-1
S1-KEY-2
WITH DUPLICATES IN ORDER
USING INPUT-FILE
OUTPUT PROCEDURE IS 050-CREATE-REPORT-1

THRU 300-DONE-REPORT-1.

020-DO-SECOND-REPORT.

SORT SORT-FILE2 ON ASCENDING KEY

S2-KEY-1
ON DESCENDING KEY
S2-KEY-2
USING INPUT-FILE
OUTPUT PROCEDURE IS 400-CREATE-REPORT-2

THRU 700-DONE-REPORT-2.

030-END-JOB.

DISPLAY "PROGRAM ENDED".
STOP RUN.

050-CREATE-REPORT-1 SECTION.
**********************************************************
*

*

*

*

*

Use the RETURN statement to read the sorted records. *

*

*

*

*

**********************************************************
300-DONE-REPORT-1 SECTION.
310-EXIT-REPORT-1.

EXIT.

400-CREATE-REPORT-2 SECTION.

**********************************************************
*

*

*

*

*

Use the RETURN statement to read the sorted records. *

*

*

*

*

**********************************************************
700-DONE-REPORT-2 SECTION.
710-EXIT-REPORT.

EXIT.

9.1.8 Sorting Variable-Length Records

If you specify the USING phrase and the input file contains variable-length
records, the sort-file record must not be smaller than the smallest record, nor
larger than the largest record, described in the input file.

9–8 Using the SORT and MERGE Statements