I'm encountering compilation errors in my COBOL program, where the compiler is indicating that file names like 'INPUT-FILE' and 'OUTPUT-FILE' are not defined. Despite defining these files in the FILE SECTION of the program, the compiler seems unable to recognize them. I've tried adjusting the I/O setup, but the errors persist. Can anyone help me understand why these errors are occurring and how to resolve them? Below is a snippet of my COBOL code for reference.
abc.cob:6: error: 'INPUT-FILE' is not defined
abc.cob:6: error: 'INPUT-FILE' is not a file name
abc.cob:11: error: 'OUTPUT-FILE' is not defined
abc.cob:11: error: 'OUTPUT-FILE' is not a file name
abc.cob:44: error: 'INPUT-FILENAME' is not defined
abc.cob:45: error: 'INPUT-FILENAME' is not a file name
abc.cob:46: error: 'OUTPUT-FILE' is not a file name
abc.cob: in paragraph 'PROC-BODY':
abc.cob:62: error: 'INPUT-FILE' is not a file name
abc.cob: in paragraph 'INPUT-LOOP':
abc.cob:87: error: 'INPUT-FILE' is not a file name
abc.cob: in paragraph 'END-OF-JOB':
abc.cob:94: error: 'INPUT-FILE' is not a file name
abc.cob:94: error: 'OUTPUT-FILE' is not a file name
I've tried adjusing I/O setup, and nothing.
IDENTIFICATION DIVISION.
PROGRAM-ID. Calculate-Mean-StdDev.
DATA DIVISION.
FILE SECTION.
FD INPUT-FILE.
01 INPUT-VALUE-RECORD.
02 IN-X PIC S9(6)V9(2).
02 FILLER PIC X(72).
FD OUTPUT-FILE.
01 OUTPUT-RECORD.
02 OUTPUT-LINE PIC X(80).
WORKING-STORAGE SECTION.
77 SUM-OF-X-SQR PIC 9(14)V9(2).
77 SUM-OF-X PIC S9(10)V9(2).
77 N PIC S9(4).
77 MEAN PIC S9(6)V9(2).
77 I PIC S9(4).
01 ARRAY-AREA.
02 X PIC S9(6)V9(2) OCCURS 1000 TIMES.
01 OUTPUT-TITLE-LINE.
02 FILLER PIC X(28) VALUE
" MEAN AND STANDARD DEVIATION".
01 OUTPUT-UNDERLINE.
02 FILLER PIC X(28) VALUE
"----------------------------".
01 OUTPUT-COL-HEADS.
02 FILLER PIC X(10) VALUE SPACES.
02 FILLER PIC X(11) VALUE "DATA VALUES".
01 OUTPUT-DATA-LINE.
02 FILLER PIC X(10) VALUE SPACES.
02 OUT-X PIC -(6)9.9(2).
01 OUTPUT-RESULTS-LINE-1.
02 FILLER PIC X(9) VALUE " MEAN= ".
02 OUT-MEAN PIC -(6)9.9(2).
01 OUTPUT-RESULTS-LINE-2.
02 FILLER PIC X(9) VALUE " STD DEV=".
02 STD-DEVIATION PIC -(6)9.9(2).
PROCEDURE DIVISION.
DISPLAY "Enter the input file name: "
ACCEPT INPUT-FILENAME
OPEN INPUT INPUT-FILENAME
OUTPUT OUTPUT-FILE.
MOVE ZERO TO IN-X.
PERFORM PROC-BODY
UNTIL IN-X IS NOT LESS THAN 999999.99.
PERFORM END-OF-JOB.
PROC-BODY.
WRITE OUTPUT-RECORD FROM OUTPUT-TITLE-LINE
AFTER ADVANCING 0 LINES.
WRITE OUTPUT-RECORD FROM OUTPUT-UNDERLINE
AFTER ADVANCING 1 LINE.
WRITE OUTPUT-RECORD FROM OUTPUT-COL-HEADS
AFTER ADVANCING 1 LINE.
WRITE OUTPUT-RECORD FROM OUTPUT-UNDERLINE
AFTER ADVANCING 1 LINE.
MOVE ZERO TO SUM-OF-X.
READ INPUT-FILE INTO INPUT-VALUE-RECORD
AT END PERFORM END-OF-JOB.
PERFORM INPUT-LOOP
VARYING N FROM 1 BY 1
UNTIL N IS GREATER THAN 1000 OR IN-X IS NOT LESS THAN 999999.98.
SUBTRACT 1 FROM N.
DIVIDE N INTO SUM-OF-X GIVING MEAN ROUNDED.
MOVE ZERO TO SUM-OF-X-SQR.
PERFORM SUM-LOOP
VARYING I FROM 1 BY 1
UNTIL I IS GREATER THAN N.
COMPUTE STD-DEVIATION ROUNDED = (SUM-OF-X-SQR / N) ** 0.5.
WRITE OUTPUT-RECORD FROM OUTPUT-UNDERLINE
AFTER ADVANCING 1 LINE.
MOVE MEAN TO OUT-MEAN.
WRITE OUTPUT-RECORD FROM OUTPUT-RESULTS-LINE-1
AFTER ADVANCING 1 LINE.
WRITE OUTPUT-RECORD FROM OUTPUT-RESULTS-LINE-2
AFTER ADVANCING 1 LINE.
INPUT-LOOP.
MOVE IN-X TO X(N), OUT-X.
WRITE OUTPUT-RECORD FROM OUTPUT-DATA-LINE
AFTER ADVANCING 1 LINE.
ADD X(N) TO SUM-OF-X.
READ INPUT-FILE INTO INPUT-VALUE-RECORD
AT END PERFORM END-OF-JOB.
SUM-LOOP.
COMPUTE SUM-OF-X-SQR = SUM-OF-X-SQR + (X(I) - MEAN) ** 2.
END-OF-JOB.
CLOSE INPUT-FILE, OUTPUT-FILE.
STOP RUN.
I 've tried adjusting the I/O setup, but the errors persist. Can anyone help me understand why these errors are occurring and how to resolve them? Below is a snippet of my COBOL code for reference.
Between your Identification Division and your Data Division you need an Environment Division, in which you need an Input-Output Section, in which you need a File-Control paragraph, in which you need to code Select statements for your files.
The above is just freehand, not tested, presuming GNU COBOL as you are using their extension where the target of the
Assign Tocan be a variable.You will need to change your code so that the
INPUT-FILEvariable into which theACCEPTstatement places the file name and the file name in theSELECTanFDstatements are different, above I did that withINPUT-FILE-NAME.There may be other problems in your code, I didn't do an exhaustive analysis.