IDENTIFICATION DIVISION.
PROGRAM-ID. EmployeeBonusCalculator.

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
    SELECT EMPLOYEE-FILE ASSIGN TO 'EMPLOYEE.DAT' ORGANIZATION IS LINE SEQUENTIAL.
    SELECT BONUS-REPORT ASSIGN TO 'BONUS_REPORT.TXT' ORGANIZATION IS LINE SEQUENTIAL.

DATA DIVISION.
FILE SECTION.
FD EMPLOYEE-FILE.
01 EMPLOYEE-RECORD.
   05 EMPLOYEE-ID PIC 9(5).
   05 EMPLOYEE-NAME PIC X(25).
   05 ANNUAL-SALARY-STR PIC X(9).
   05 PERFORMANCE-RATING-STR PIC X.

FD BONUS-REPORT.
01 BONUS-RECORD PIC A(80).

WORKING-STORAGE SECTION.
01 END-OF-FILE PIC X VALUE 'N'.
   88 EOF VALUE 'Y'.
   88 NOT-EOF VALUE 'N'.
01 BONUS-RATE PIC V99 VALUE ZEROS.
01 BONUS-AMOUNT PIC 9(7)V99 VALUE ZEROS.
01 REPORT-LINE PIC A(80).
01 WS-ANNUAL-SALARY-NUM PIC 9(7)V99 VALUE ZEROS.
01 WS-PERFORMANCE-RATING-NUM PIC 9 VALUE ZEROS.

PROCEDURE DIVISION.
000-MAIN.
    OPEN INPUT EMPLOYEE-FILE
         OUTPUT BONUS-REPORT
    PERFORM UNTIL EOF
        READ EMPLOYEE-FILE INTO EMPLOYEE-RECORD
            AT END
                SET EOF TO TRUE
            NOT AT END
                DISPLAY "Reading Employee ID: " EMPLOYEE-ID
                DISPLAY "Employee Name: " EMPLOYEE-NAME

                *> Convert the annual salary string to a numeric value
                MOVE FUNCTION NUMVAL(ANNUAL-SALARY-STR) TO WS-ANNUAL-SALARY-NUM
                DISPLAY "Annual Salary: " WS-ANNUAL-SALARY-NUM

                *> Convert the performance rating string to a numeric value
                MOVE FUNCTION NUMVAL(PERFORMANCE-RATING-STR) TO WS-PERFORMANCE-RATING-NUM
                DISPLAY "Performance Rating: " WS-PERFORMANCE-RATING-NUM

                EVALUATE WS-PERFORMANCE-RATING-NUM
                    WHEN 1 THRU 2
                        MOVE 0 TO BONUS-RATE
                    WHEN 3
                        MOVE 0.10 TO BONUS-RATE
                    WHEN 4 THRU 5
                        MOVE 0.20 TO BONUS-RATE
                    WHEN OTHER
                        MOVE 0 TO BONUS-RATE
                END-EVALUATE

                COMPUTE BONUS-AMOUNT = WS-ANNUAL-SALARY-NUM * BONUS-RATE / 100
                MOVE SPACES TO REPORT-LINE

                STRING EMPLOYEE-NAME " - Rating: " WS-PERFORMANCE-RATING-NUM
                       " - Bonus: $" BONUS-AMOUNT DELIMITED BY SIZE INTO REPORT-LINE
                WRITE BONUS-RECORD FROM REPORT-LINE
        END-READ
    END-PERFORM

    CLOSE EMPLOYEE-FILE
          BONUS-REPORT
    STOP RUN.
