Compaq COBOL AAQ2G1FTK User Manual

Page 295

Advertising
background image

Using the SORT and MERGE Statements

9.3 Sample Programs Using the SORT and MERGE Statements

Example 9–10 (Cont.) Using the COLLATING SEQUENCE IS Phrase

FD

INPUT-FILE
LABEL RECORDS ARE STANDARD.

01

IN-REC

PIC X(30).

FD

OUTPUT-FILE
LABEL RECORDS ARE STANDARD.

01

OUT-REC

PIC X(30).

PROCEDURE DIVISION.
000-DO-THE-SORT.

SORT SORT-FILE ON ASCENDING KEY

S-KEY-1
S-KEY-2

COLLATING SEQUENCE IS MYSEQUENCE
USING INPUT-FILE GIVING OUTPUT-FILE.

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

At this point, you could transfer control to another

*

*

section of the program and continue processing.

*

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

DISPLAY "END OF PROGRAM SORTD".
STOP RUN.

Example 9–11 is an example of creating a new sort key.

Example 9–11 Creating a New Sort Key

IDENTIFICATION DIVISION.
PROGRAM-ID. SORTE.
************************************************
*

This program increases the size of the

*

*

variable input records by a new six-

*

*

character field and uses this field

*

*

as the sort key.

*

************************************************
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.

SELECT INFILE ASSIGN TO "INFILE".
SELECT SORT-FILE ASSIGN TO "SRTFIL".
SELECT OUT-FILE ASSIGN TO "OUTFILE".

DATA DIVISION.
FILE SECTION.
FD

INFILE
RECORD VARYING FROM 100 TO 490 CHARACTERS
DEPENDING ON IN-LENGTH.

01

INREC.
03 ACCOUNT

PIC 9(5).

03 INCOME-FIRST-QUARTER

PIC 9(5)V99.

03 INCOME-SECOND-QUARTER

PIC 9(5)V99.

03 INCOME-THIRD-QUARTER

PIC 9(5)V99.

(continued on next page)

Using the SORT and MERGE Statements 9–17

Advertising