-----------------------------------------------------------------------
     Note that in some COBOL compilers the FD area becomes unavailable after
     end-of-file is encountered.
     This code does not access the next-record area after end-of-file.
     -----------------------------------------------------------------------
     
     IDENTIFICATION DIVISION.
     PROGRAM-ID. "SMAINLIN".
     AUTHOR. ALFRED SIMPSON.
     ENVIRONMENT DIVISION.
     
     INPUT-OUTPUT SECTION.
     FILE-CONTROL.
     SELECT SALES-FILE ASSIGN TO INFILE
     ORGANIZATION IS LINE SEQUENTIAL.
     

     SELECT REPORT-FILE ASSIGN TO PRNTFILE
     ORGANIZATION IS LINE SEQUENTIAL.
     DATA DIVISION.
     
     FILE SECTION.
     FD SALES-FILE
     RECORD CONTAINS 60 CHARACTERS
     DATA RECORD IS NEXT-RECORD.
     
     01  NEXT-RECORD.
         05 FILLER                      PIC X(2).
         05 FILLER                      PIC X(20).
         05 FILLER                      PIC X(30).
     
         05 FILLER                      PIC S9(6)V9(2).

     FD REPORT-FILE
     DATA RECORD IS REPORT-RECORD.
     
     01  REPORT-RECORD                  PIC X(80).

     WORKING-STORAGE SECTION.
     01  CURRENT-RECORD.
     
         05  CURRENT-STATE              PIC X(2).
         05  CURRENT-CITY               PIC X(20).
         05  CURRENT-CUSTOMER           PIC X(30).
         05  CURRENT-AMOUNT             PIC S9(6)V9(2).
     

     01  LEVEL-CONTROL                  PIC 9999 VALUE 99.

     01  CUSTOMER-DETAIL.
     
         05  FILLER                     PIC X(2) VALUE SPACES.
         05  LN01-STATE                 PIC X(2).
         05  FILLER                     PIC X(5) VALUE SPACES.
         05  LN01-CITY                  PIC X(20).
     
         05  FILLER                     PIC X(5) VALUE SPACES.
         05  LN01-CUSTOMER              PIC X(30).
         05  FILLER                     PIC X(5) VALUE SPACES.
         05  LN01-AMOUNT                PIC ----,--9.99.
     

     PROCEDURE DIVISION.

     PROCEDURE-MAIN.
     
         PERFORM PROGRAM-INITIAL.
         PERFORM MAIN-LINE            UNTIL LEVEL-CONTROL = 100.
         PERFORM PROGRAM-SUMMARY.
         STOP RUN.
     

     PROGRAM-INITIAL.
         OPEN INPUT SALES-FILE.
         OPEN OUTPUT REPORT-FILE.
     
         PERFORM GET-NEXT-RECORD.

     PROGRAM-SUMMARY.
         CLOSE SALES-FILE REPORT-FILE.
     

     MAIN-LINE.
         MOVE NEXT-RECORD               TO CURRENT-RECORD.
         MOVE CURRENT-STATE             TO LN01-STATE.
     
         MOVE CURRENT-CITY              TO LN01-CITY.
         MOVE CURRENT-CUSTOMER          TO LN01-CUSTOMER.
         MOVE CURRENT-AMOUNT            TO LN01-AMOUNT.
         WRITE REPORT-RECORD          FROM CUSTOMER-DETAIL.
     
         PERFORM GET-NEXT-RECORD.

     GET-NEXT-RECORD.
         READ SALES-FILE AT END MOVE 100 TO LEVEL-CONTROL END-READ.