Compaq AAQ2G1FTK Marine Radio User Manual


 
Using the SORT and MERGE Statements
9.3 Sample Programs Using the SORT and MERGE Statements
Example 97 Sorting a File with the USING and GIVING Phrases
IDENTIFICATION DIVISION.
PROGRAM-ID. SORTA.
*************************************************
* This program shows how to sort *
* a file with the USING and GIVING phrases *
* of the SORT statement. 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 OUTPUT-FILE is a relative file. *
*************************************************
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT INPUT-FILE ASSIGN TO "INPFIL".
SELECT OUTPUT-FILE ASSIGN TO "OUTFIL"
ORGANIZATION IS RELATIVE.
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.
01 OUT-REC PIC X(100).
PROCEDURE DIVISION.
000-DO-THE-SORT.
SORT SORT-FILE ON ASCENDING KEY
S-KEY-1
S-KEY-2
WITH DUPLICATES IN ORDER
USING INPUT-FILE GIVING OUTPUT-FILE.
***********************************************************
* At this point, you could transfer control to another *
* section of your program and continue processing. *
***********************************************************
DISPLAY "END OF PROGRAM SORTA".
STOP RUN.
Example 9–8 shows how to use the USING and OUTPUT PROCEDURE phrases.
Using the SORT and MERGE Statements 911