How to use PERFORM TEST AFTER logic in COBOL

Perform with Test after usage in COBOL program.

IDENTIFICATION DIVISION.
       PROGRAM-ID.  Empage.
      *****************************************************************
      * PROGRAM TO READ INPUT FILE, COMPUTE PERSON'S AGE, AND WRITE   *
      * OUTPUT FILE.                                                  *
      * IN:  In-File CONTAINS INPUT FILE.                             *
      * OUT: Out-File CONTAINS INPUT FILE RECORDS WITH AGE ADDED.     *
      *****************************************************************
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT In-File ASSIGN TO "OLDFILE.TXT"
                  ORGANIZATION IS LINE SEQUENTIAL.
           SELECT Out-File ASSIGN TO "NEWFILE.TXT"
                  ORGANIZATION IS LINE SEQUENTIAL.
       DATA DIVISION.
       FILE SECTION.
       FD  In-File BLOCK CONTAINS 0 RECORDS.
       01  In-Emp.
           02  In-Name                   PIC X(30).
           02  In-Birth-Date.
               03  In-Birth-Yr           PIC 99.
               03  In-Birth-Mo           PIC 99.
               03  In-Birth-Dy           PIC 99.
           02                            PIC X.
           02  In-Hire-Date.
               03  In-Hire-Yr            PIC 99.
               03  In-Hire-Mo            PIC 99.
               03  In-Hire-Dy            PIC 99.
       FD  Out-File BLOCK CONTAINS 0 RECORDS.
       01  Out-Emp.
           02  Out-Name                  PIC X(30).
           02  Out-Birth-Date.
               03  Out-Birth-Yr          PIC 99.
               03  Out-Birth-Mo          PIC 99.
               03  Out-Birth-Dy          PIC 99.
           02                            PIC X.
           02  Out-Hire-Date.
               03  Out-Hire-Yr           PIC 99.
               03  Out-Hire-Mo           PIC 99.
               03  Out-Hire-Dy           PIC 99.
           02  Hire-Age                  PIC 999.
       WORKING-STORAGE SECTION.
       01  EOF-In-File                   PIC X.
      *            EOF-In-File is end of file flag for In-File.
      *            "N" if no EOF.  "Y" for EOF.
       PROCEDURE DIVISION.
       A00-Begin.
           OPEN INPUT In-File, OUTPUT Out-File
           PERFORM WITH TEST AFTER UNTIL EOF-In-File = "Y"
              READ In-File
                 AT END MOVE "Y" TO EOF-In-File
                 NOT AT END
                    MOVE "N" TO EOF-In-File
                    MOVE In-Emp TO Out-Emp
                    COMPUTE Hire-Age = In-Hire-Yr - In-Birth-Yr
                    IF In-Hire-Mo < In-Birth-Mo
                       THEN COMPUTE Hire-Age = Hire-Age - 1
                    END-IF
                    IF In-Hire-Mo = In-Birth-Mo AND
                       In-Hire-Dy < In-Birth-Dy
                       THEN COMPUTE Hire-Age = Hire-Age - 1
                    END-IF
                    WRITE Out-Emp
              END-READ
           END-PERFORM
           CLOSE In-File, Out-File
           GOBACK
           .
       END PROGRAM Empage.
OLDFILE.TXT:
Able, John A.                 590201 950924
Baker, Harry M.               620511 950924
Cox, Mary T.                  730330 950924
Minow, Samuel T.              681221 950924
Smith, Joseph L.              641121 950924
Zach, Thomas W.               750913 950924

Ref: Wiley-advanced cobol

Use COMPUTE coding in a better way for your COBOL programs

Sample COBOL program using COMPUTE:

 IDENTIFICATION DIVISION.
       PROGRAM-ID.  EINSTEIN.
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT In-File ASSIGN TO "EINSTEIN.TXT"
                  ORGANIZATION IS LINE SEQUENTIAL.
       DATA DIVISION.
       FILE SECTION.
       FD  IN-FILE BLOCK CONTAINS 0 RECORDS.
       01  IN-REC.
           02  M                         PIC S9(10).
           02  C                         PIC S9(10).
       WORKING-STORAGE SECTION.
       01  E                             PIC S9(10) PACKED-DECIMAL.
       PROCEDURE DIVISION.
       BEGIN-PROGRAM.
           OPEN INPUT IN-FILE
           READ IN-FILE
           COMPUTE E = M * (C ** 2)
           CLOSE IN-FILE
           GOBACK
           .
       END PROGRAM EINSTEIN.