9 Using the SORT and MERGE Statements
9.1 Sorting Data with the SORT Statement .......................... 9–1
9.1.1 File Organization Considerations for Sorting . ................... 9–2
9.1.2 Specifying Sort Parameters with the ASCENDING and
DESCENDING KEY Phrases ................................ 9–3
9.1.3 Resequencing Files with the USING and GIVING Phrases ......... 9–3
9.1.4 Manipulating Data Before and After Sorting with the INPUT
PROCEDURE and OUTPUT PROCEDURE Phrases . . . ........... 9–3
9.1.5 Maintaining the Input Order of Records Using the WITH
DUPLICATES IN ORDER Phrase ............................ 9–6
9.1.6 Specifying Non-ASCII Collating Sequences with the COLLATING
SEQUENCE IS Alphabet-Name Phrase ........................ 9–7
9.1.7 Multiple Sorting .......................................... 9–7
9.1.8 Sorting Variable-Length Records . ............................ 9–8
9.1.9 Preventing I/O Aborts . .................................... 9–9
9.1.10 Sorting Tables ........................................... 9–9
9.1.11 Sorting at the Operating System Level ........................ 9–9
9.2 Merging Data with the MERGE Statement ........................ 9–10
9.3 Sample Programs Using the SORT and MERGE Statements .......... 9–10
10 Producing Printed Reports
10.1 Designing a Report .......................................... 10–1
10.2 Components of a Report . . . .................................... 10–1
10.3 Accumulating and Reporting Totals . . ............................ 10–4
10.4 The Logical Page and the Physical Page .......................... 10–5
10.5 Programming a Conventional File Report ......................... 10–6
10.5.1 Defining the Logical Page in a Conventional Report . . . ........... 10–6
10.5.2 Controlling the Spacing in a Conventional Report ................ 10–7
10.5.3 Advancing to the Next Logical Page in a Conventional Report . . . . . . 10–7
10.5.3.1 Programming for the Page-Overflow Condition in a Conventional
Report . . ............................................ 10–7
10.5.3.2 Using a Line Counter................................... 10–8
10.5.4 Printing the Conventional Report ............................ 10–9
10.5.5 A Conventional File Report Example .......................... 10–9
10.6 Programming a Linage-File Compaq COBOL Report ................. 10–12
10.6.1 Defining the Logical Page in a Linage-File Report ................ 10–13
10.6.2 Controlling the Spacing in a Linage-File Report ................. 10–14
10.6.3 Using the LINAGE-COUNTER . . ............................ 10–14
10.6.4 Advancing to the Next Logical Page in a Linage-File Report ........ 10–14
10.6.5 Programming for the End-of-Page and Page-Overflow Condition . . . . . 10–15
10.6.6 Printing a Linage-File Report . . . ............................ 10–19
10.6.7 A Linage-File Report Example . . . ............................ 10–20
10.7 Modes for Printing Reports .................................... 10–23
10.7.1 Directly Allocating a Printer ................................ 10–23
10.7.2 Spooling to a Mass Storage Device ............................ 10–24
10.8 Programming a Report Writer Report ............................ 10–24
10.8.1 Using the REPORT Clause in the File Section .................. 10–25
10.8.2 Defining the Report Section and the Report File ................. 10–25
10.8.3 Defining a Report Writer Logical Page with the PAGE Clause . . . . . . 10–25
10.8.4 Describing Report Group Description Entries ................... 10–26
10.8.5 Vertical Spacing for the Logical Page .......................... 10–29
10.8.6 Horizontal Spacing for the Logical Page ....................... 10–30
10.8.7 Assigning a Value in a Print Line ............................ 10–31
viii