Using The Using And Output Procedure Phrases - Compaq COBOL AAQ2G1FTK User Manual

Compaq computer accessories user manual
Table of Contents

Advertisement

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"
SELECT SORT-FILE ASSIGN TO "SRTFIL".
DATA DIVISION.
FILE SECTION.
SD SORT-FILE.
01 SORT-REC.
03 S-KEY-1.
03 FILLER
03 S-KEY-2.
03 FILLER
FD INPUT-FILE
LABEL RECORDS ARE STANDARD.
01 IN-REC
FD OUTPUT-FILE
LABEL RECORDS ARE STANDARD
ACCESS MODE IS SEQUENTIAL
RECORD KEY IS OUT-KEY.
01 OUT-REC.
03 OUT-KEY
03 FILLER
WORKING-STORAGE SECTION.
01 INITIAL-SORT-READ
01 SAVE-SORT-REC.
03 SR-ACCOUNT-NUM
03 FILLER
03 SR-AMOUNT
03 FILLER
PROCEDURE DIVISION.
000-START SECTION.
005-DO-THE-SORT.
SORT SORT-FILE ON ASCENDING KEY
9–12 Using the SORT and MERGE Statements
ORGANIZATION IS INDEXED.
05 S-ACCOUNT-NUM
05 S-AMOUNT
S-KEY-1
S-KEY-2
PIC X(8).
PIC X(32).
PIC S9(5)V99.
PIC X(53).
PIC X(100).
PIC X(8).
PIC X(92).
PIC X
VALUE "Y".
PIC X(8).
PIC X(32).
PIC S9(5)V99.
PIC X(53).
*
*
*
*
*
*
*
*
*
*
(continued on next page)

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the COBOL AAQ2G1FTK and is the answer not in the manual?

Table of Contents