Compaq AAQ2G1FTK Marine Radio User Manual


 
Using the SORT and MERGE Statements
9.3 Sample Programs Using the SORT and MERGE Statements
Example 911 (Cont.) Creating a New Sort Key
120-WRITE.
RETURN SORT-FILE AT END
CLOSE OUT-FILE
GO TO 130-DONE.
MOVE SORT-LENGTH TO OUT-LENGTH.
WRITE OUT-REC.
GO TO 120-WRITE.
130-DONE.
EXIT.
Example 9–12 merges three identically sequenced files into one file.
Example 912 Merging Files
IDENTIFICATION DIVISION.
PROGRAM-ID. MERGE01.
******************************************************
* This program merges three identically sequenced *
* regional sales files into one total sales file. *
* The program adds sales amounts and writes one *
* record for each product code. *
******************************************************
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT REGION1-SALES ASSIGN TO "REG1SLS".
SELECT REGION2-SALES ASSIGN TO "REG2SLS".
SELECT REGION3-SALES ASSIGN TO "REG3SLS".
SELECT MERGE-FILE ASSIGN TO "MRGFILE".
SELECT TOTAL-SALES ASSIGN TO "TOTLSLS".
DATA DIVISION.
FILE SECTION.
FD REGION1-SALES
LABEL RECORDS ARE STANDARD.
01 REGION1-RECORD PIC X(100).
FD REGION2-SALES
LABEL RECORDS ARE STANDARD.
01 REGION2-RECORD PIC X(100).
FD REGION3-SALES
LABEL RECORDS ARE STANDARD.
01 REGION3-RECORD PIC X(100).
SD MERGE-FILE.
01 MERGE-REC.
03 M-REGION-CODE PIC XX.
03 M-PRODUCT-CODE PIC X(10).
03 M-SALES-AMT PIC S9(7)V99.
03 FILLER PIC X(79).
(continued on next page)
Using the SORT and MERGE Statements 919