I have the following Gnu Cobol code:
IDENTIFICATION DIVISION.
PROGRAM-ID. INCOME-TAX-CALCULATOR.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT EMPLOYEE-FILE
ASSIGN TO "employees.csv"
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD EMPLOYEE-FILE.
01 EMPLOYEE-RECORD.
02 EMP-ID PIC 9(5).
02 EMP-NAME PIC X(30).
02 EMP-SALARY PIC 9(7).
02 EMP-TAX PIC 9(5).
WORKING-STORAGE SECTION.
01 WS-TAX-RATE PIC 9(4)V99 VALUE 20.
PROCEDURE DIVISION.
OPEN INPUT EMPLOYEE-FILE
PERFORM UNTIL EOF
READ EMPLOYEE-FILE
AT END SET EOF TO TRUE
END-READ
COMPUTE EMP-TAX = EMP-SALARY * WS-TAX-RATE
DISPLAY EMP-ID, EMP-NAME, EMP-SALARY, EMP-TAX
END-PERFORM
CLOSE EMPLOYEE-FILE
STOP RUN.
in GnuCobol 3.1.2.0 I get the following error:
programName:25: error: 'EOF' is not defined
I have seen similar questions but END PROGRAM
does not help.
I use the compiler with the free format like this: cobc -x -F -o programName programName.cbl
You've missed a definition for that EOF, so it is... undefined.
adding a definition like the following in WORKING-STORAGE-SECTION
would solve that:
01 FILLER PIC X VALUE ' '.
88 EOF VALUE 'E'.
but you'd likely define a "NOT-EOF" or similar and set it before that loop, or, even better get rid of it completely:
PERFORM UNTIL EXIT
READ EMPLOYEE-FILE
AT END EXIT PERFORM
END-READ
COMPUTE EMP-TAX = EMP-SALARY * WS-TAX-RATE
DISPLAY EMP-ID, EMP-NAME, EMP-SALARY, EMP-TAX
END-PERFORM
... but you'd likely still want to add checks for "did the OPEN work", but that's a different question, if at all.