000010  IDENTIFICATION DIVISION.
000020    PROGRAM-ID. READFILE.
000030    AUTHOR. Dan Ruscoe.
000040  ENVIRONMENT DIVISION.
000050    INPUT-OUTPUT SECTION.
000060      FILE-CONTROL.
000070        SELECT DATA-FILE ASSIGN TO "data/presidents.txt"
000080          ORGANIZATION IS LINE SEQUENTIAL.
000090  DATA DIVISION.
000100    FILE SECTION.
000110      FD DATA-FILE.
000120        01 IN-RECORD.
000130          05 PRESIDENCY         PIC 9(2).
000140          05 PRES-NAME          PIC X(17).
000150          05 PRES-START-DATE    PIC X(10).
000160          05 PRES-END-DATE      PIC X(10).
000170          05 PRES-HOME-STATE    PIC X(13).
000180    WORKING-STORAGE SECTION.
000190      01 SWITCHES.
000200        05 EOF-SWITCH     PIC X VALUE "N".
000210      01 COUNTERS.
000220        05 REC-COUNTER    PIC 9(3) VALUE 0.
000230  PROCEDURE DIVISION.
000240    000-MAIN.
000250      PERFORM 100-INITIALIZE.
000260      PERFORM 200-PROCESS-RECORDS
000270        UNTIL EOF-SWITCH = "Y"
000280      PERFORM 300-COMPLETE.
000290      STOP RUN.
000300    100-INITIALIZE.
000310      OPEN INPUT DATA-FILE.
000320      READ DATA-FILE
000330        AT END
000340          MOVE "Y" TO EOF-SWITCH
000350        NOT AT END
000360          COMPUTE REC-COUNTER = REC-COUNTER + 1
000370      END-READ.
000380    200-PROCESS-RECORDS.
000390      DISPLAY "PRESIDENT NAME       :  " PRES-NAME.
000400      DISPLAY "PRESIDENT FROM       :  " PRES-START-DATE.
000410      DISPLAY "PRESIDENT TO         :  " PRES-END-DATE.
000420      DISPLAY "PRESIDENT HOME STATE :  " PRES-HOME-STATE.
000430      DISPLAY "---"
000440      READ DATA-FILE
000450        AT END
000460          MOVE "Y" TO EOF-SWITCH
000470        NOT AT END
000480          COMPUTE REC-COUNTER = REC-COUNTER + 1
000490      END-READ.
000500    300-COMPLETE.
000510      CLOSE DATA-FILE.
