Using the SORT and MERGE Statements
9.3 Sample Programs Using the SORT and MERGE Statements
Example 9–8 Using the USING and OUTPUT PROCEDURE Phrases
IDENTIFICATION DIVISION.
PROGRAM-ID. SORTB.
**************************************************************
*
This program shows how to sort a file
*
*
with the USING and OUTPUT PROCEDURE phrases
*
*
of the SORT statement. The program eliminates
*
*
duplicate records by adding their amounts to the
*
*
amount in the first record with the same account
*
*
number. Only records with unique account numbers
*
*
are written to the output file. The fields to be
*
*
sorted are S-KEY-1 and S-KEY-2; they contain account
*
*
numbers and amounts. The sort sequence is amount
*
*
within account number.
*
*
Notice that the organization of OUTPUT-FILE is indexed.
*
**************************************************************
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT INPUT-FILE ASSIGN TO "INPFIL".
SELECT OUTPUT-FILE ASSIGN TO "OUTFIL"
ORGANIZATION IS INDEXED.
SELECT SORT-FILE ASSIGN TO "SRTFIL".
DATA DIVISION.
FILE SECTION.
SD
SORT-FILE.
01
SORT-REC.
03
S-KEY-1.
05
S-ACCOUNT-NUM
PIC X(8).
03
FILLER
PIC X(32).
03
S-KEY-2.
05
S-AMOUNT
PIC S9(5)V99.
03
FILLER
PIC X(53).
FD
INPUT-FILE
LABEL RECORDS ARE STANDARD.
01
IN-REC
PIC X(100).
FD
OUTPUT-FILE
LABEL RECORDS ARE STANDARD
ACCESS MODE IS SEQUENTIAL
RECORD KEY IS OUT-KEY.
01
OUT-REC.
03
OUT-KEY
PIC X(8).
03
FILLER
PIC X(92).
WORKING-STORAGE SECTION.
01
INITIAL-SORT-READ
PIC X
VALUE "Y".
01
SAVE-SORT-REC.
03
SR-ACCOUNT-NUM
PIC X(8).
03
FILLER
PIC X(32).
03
SR-AMOUNT
PIC S9(5)V99.
03
FILLER
PIC X(53).
PROCEDURE DIVISION.
000-START SECTION.
005-DO-THE-SORT.
SORT SORT-FILE ON ASCENDING KEY
S-KEY-1
S-KEY-2
(continued on next page)
9–12 Using the SORT and MERGE Statements
Содержание COBOL AAQ2G1FTK
Страница 22: ......
Страница 30: ......
Страница 94: ......
Страница 110: ......
Страница 146: ......
Страница 180: ......
Страница 194: ...Processing Files and Records 6 1 Defi...
Страница 300: ......
Страница 490: ......
Страница 516: ......
Страница 517: ......
Страница 530: ......
Страница 534: ......
Страница 590: ......
Страница 620: ......