Maintaining The Input Order Of Records Using The With Duplicates In Order Phrase; Using Phrase Replaces Input Procedure Phrase - Compaq COBOL AAQ2G1FTK User Manual

Compaq computer accessories user manual
Table of Contents

Advertisement

Using the SORT and MERGE Statements
9.1 Sorting Data with the SORT Statement
Example 9–2 USING Phrase Replaces INPUT PROCEDURE Phrase
.
.
.
PROCEDURE DIVISION.
000-SORT SECTION.
010-DO-THE-SORT.
SORT SORT-FILE ON ASCENDING KEY SORT-KEY-1
DISPLAY "END OF SORT".
STOP RUN.
200-WRITE-OUTPUT SECTION.
210-OPEN-OUTPUT.
OPEN OUTPUT OUTPUT-FILE.
220-GET-SORTED-RECORDS.
RETURN SORT-FILE AT END
MOVE SORT-RECORD TO OUTPUT-RECORD.
WRITE OUTPUT-RECORD.
GO TO 220-GET-SORTED-RECORDS.
230-DONE-OUTPUT SECTION.
240-EXIT-OUTPUT.
EXIT.
9.1.5 Maintaining the Input Order of Records Using the WITH DUPLICATES IN
ORDER Phrase
The sort orders data in the sequence specified in the ASCENDING KEY and
DESCENDING KEY phrases. However, records with duplicate sort keys may not
be written to the output file in the same sequence as they were read into it. The
WITH DUPLICATES IN ORDER phrase ensures that any records with duplicate
sort keys are in the same order in the output file as in the input file.
The following list shows the potential difference between sorting with the WITH
DUPLICATES IN ORDER phrase and sorting without it:
Input File
Record
Name
JONES ABCD
DAVIS LMNO
WHITE STUV
JONES EFGH
SMITH 1234
WHITE WXYZ
If you omit the WITH DUPLICATES IN ORDER phrase, you cannot predict
the order of records with duplicate sort keys. For example, the JONES records
might not be in the same sequence as they were in the input file, but the WHITE
records might be in the same order as in the input file.
9–6 Using the SORT and MERGE Statements
ON DESCENDING KEY SORT-KEY-2
USING INPUT-FILE
OUTPUT PROCEDURE IS 200-WRITE-OUTPUT
CLOSE OUTPUT-FILE
GO TO 230-DONE-OUTPUT.
Sorted Without
Duplicates in Order
Record
Data
Name
DAVIS LMNO
JONES EFGH
JONES ABCD
SMITH 1234
WHITE STUV
WHITE WXYZ
THRU 230-DONE-OUTPUT.
Sorted With
Duplicates in Order
Record
Data
Name
DAVIS LMNO
JONES ABCD
JONES EFGH
SMITH 1234
WHITE STUV
WHITE WXYZ
Data

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the COBOL AAQ2G1FTK and is the answer not in the manual?

Subscribe to Our Youtube Channel

Table of Contents