 IDENTIFICATION DIVISION.
 ENVIRONMENT DIVISION.
 INPUT-OUTPUT SECTION.
 FILE-CONTROL.
     SELECT INPUT-FILE       ASSIGN TO DISK
                             ORGANIZATION IS LINE SEQUENTIAL.
     SELECT OPTIONAL
            APPEND-FILE      ASSIGN TO DISK
                             ORGANIZATION IS LINE SEQUENTIAL.
 DATA DIVISION.
 FILE SECTION.

 FD  INPUT-FILE
     VALUE OF FILE-ID IS "INPUT.DAT".
 01  INPUT-RECORD.
     03  INPUT-NAME              PIC  X(30).
     03  INPUT-ADDR-1            PIC  X(30).
     03  INPUT-ADDR-2            PIC  X(30).
     03  INPUT-PHONE             PIC  X(16).

 FD  APPEND-FILE
     VALUE OF FILE-ID IS "APPEND.DAT".
 01  APPEND-RECORD.
     03  APPEND-NAME             PIC  X(30).
     03  APPEND-ADDR-1           PIC  X(30).
     03  APPEND-ADDR-2           PIC  X(30).
     03  APPEND-PHONE            PIC  X(16).

 WORKING-STORAGE SECTION.
 77  WS-END-FLAG                 PIC  9(01)      VALUE 0.
 77  WS-COUNT                    PIC  9(06) COMP VALUE 0.

 PROCEDURE DIVISION.

 000000-CONTROL.
     PERFORM 000100-INITIALIZE.
     PERFORM 000200-PROCESS
         UNTIL (WS-END-FLAG = 1).
     PERFORM 000300-TERMINATE.
     STOP RUN.

 000100-INITIALIZE.
     OPEN INPUT  INPUT-FILE
          EXTEND APPEND-FILE.
     READ INPUT-FILE
         AT END
             MOVE 1 TO WS-END-FLAG
     END-READ.

 000200-PROCESS.
     INITIALIZE APPEND-RECORD.
     MOVE INPUT-NAME   TO APPEND-NAME.
     MOVE INPUT-ADDR-1 TO APPEND-ADDR-1.
     MOVE INPUT-ADDR-2 TO APPEND-ADDR-2.
     MOVE INPUT-PHONE  TO APPEND-PHONE.
     WRITE APPEND-RECORD.
     ADD 1 TO WS-COUNT.
     READ INPUT-FILE
         AT END
             MOVE 1 TO WS-END-FLAG
     END-READ.

 000300-TERMINATE.
     CLOSE INPUT-FILE
           APPEND-FILE.
     DISPLAY WS-COUNT " records".
