Using the SORT and MERGE Statements
9.3 Sample Programs Using the SORT and MERGE Statements
Example 9–8 (Cont.) Using the USING and OUTPUT PROCEDURE Phrases
USING INPUT-FILE
OUTPUT PROCEDURE IS 300-CREATE-OUTPUT-FILE
THRU 600-DONE-CREATE.
************************************************************
*
At this point, you could transfer control to another
*
*
section of the program and continue processing.
*
************************************************************
DISPLAY "END OF PROGRAM SORTB".
STOP RUN.
300-CREATE-OUTPUT-FILE SECTION.
350-OPEN-OUTPUT.
OPEN OUTPUT OUTPUT-FILE.
400-READ-SORT-FILE.
RETURN SORT-FILE AT END
PERFORM 500-WRITE-THE-OUTPUT
CLOSE OUTPUT-FILE
GO TO 600-DONE-CREATE.
IF INITIAL-SORT-READ = "Y"
MOVE SORT-REC TO SAVE-SORT-REC
MOVE "N" TO INITIAL-SORT-READ
GO TO 400-READ-SORT-FILE.
450-COMPARE-ACCOUNT-NUM.
IF S-ACCOUNT-NUM = SR-ACCOUNT-NUM
ADD S-AMOUNT TO SR-AMOUNT
GO TO 400-READ-SORT-FILE.
500-WRITE-THE-OUTPUT.
MOVE SAVE-SORT-REC TO OUT-REC.
WRITE OUT-REC INVALID KEY
DISPLAY "INVALID KEY " SR-ACCOUNT-NUM " SORTB ABORTED"
CLOSE OUTPUT-FILE STOP RUN.
550-GET-A-REC.
MOVE SORT-REC TO SAVE-SORT-REC.
GO TO 400-READ-SORT-FILE.
600-DONE-CREATE SECTION.
650-EXIT-PARAGRAPH.
EXIT.
Example 9–9 shows how to use the INPUT PROCEDURE and OUTPUT
PROCEDURE phrases.
Using the SORT and MERGE Statements 9–13