9.3 Sample Programs Using the SORT and MERGE Statements
Example 9–7 Sorting a File with the USING and GIVING Phrases
IDENTIFICATION DIVISION.
PROGRAM-ID.
*************************************************
*
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
03 FILLER
03 S-KEY-2.
05 S-AMOUNT
03 FILLER
FD INPUT-FILE
LABEL RECORDS ARE STANDARD.
01 IN-REC
FD OUTPUT-FILE
LABEL RECORDS ARE STANDARD.
01 OUT-REC
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
SORTA.
PIC X(8).
PIC X(32).
PIC S9(5)V99.
PIC X(53).
PIC X(100).
PIC X(100).
Using the SORT and MERGE Statements 9–11
*
*
*
*
*
*
*
*
Need help?
Do you have a question about the COBOL AAQ2G1FTK and is the answer not in the manual?