sebac13
sebac13

Reputation: 65

Problems with file reading in COBOL

I just begin learning COBOL and I want read file Dane.txt. I use Microsoft COBOL Compiler Version 2.20 in Win7 (Instruction how to install this compiler was the first what I found). This is my code:

IDENTIFICATION DIVISION.
PROGRAM-ID. RAPORT.

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT IN-FILE ASSIGN TO DISK
    ORGANIZATION IS LINE SEQUENTIAL.

DATA DIVISION.

FILE SECTION.

FD IN-FILE
    DATA RECORD is INPUT-RECORD
LABEL RECORDS ARE STANDARD
    VALUE OF FILE-ID IS "C:\MYCOBOL\COBOL\Dane.TXT".
01 INPUT-REC.
    05 ID-C PIC 9(5).
    05 Name         PIC X(15).
    05 ADDRESS      PIC X(8).
    05 NIP          PIC 9(10).

WORKING-STORAGE SECTION.
01 SWITCHES.
    05 EOF-SWITCH   PIC X VALUE "N".

01 COUNTERS.
    05 REC-COUNTER  PIC 9(3) VALUE 0.


PROCEDURE DIVISION.
000-MAIN.

    PERFORM 100-INITIALIZE.
    PERFORM 200-PROCESS-RECORDS
        UNTIL EOF-SWITCH = "Y".
    PERFORM 300-TERMINATE.
    STOP RUN.

100-INITIALIZE.


    OPEN INPUT IN-FILE.

    READ IN-FILE
        AT END
            MOVE "Y" TO EOF-SWITCH
    END-READ.

200-PROCESS-RECORDS.

    DISPLAY "ID    --> " ID-C.
    DISPLAY "NAME  --> " NAME.
    DISPLAY "ADDRESS --> " ADDRESS.
    DISPLAY "NIP   --> " NIP.

    READ IN-FILE
        AT END
            MOVE "Y" TO EOF-SWITCH
    END-READ.

300-TERMINATE.
    DISPLAY "THE END".
    CLOSE IN-FILE.

I get from my compiler message that END-READ is unrecognizable element and it is ignored. I have no idea what to do next. I do research but I found nothing. Maybe is another way to read file?

Upvotes: 0

Views: 2241

Answers (2)

Jan Wout
Jan Wout

Reputation: 1

READ IN-FILE
        AT END
            MOVE "Y" TO EOF-SWITCH.

Cobol-74, end the read-statement with a period, not with END-READ (cobol-85)

Upvotes: 0

Gilbert Le Blanc
Gilbert Le Blanc

Reputation: 51445

Your compilation has 4 syntax errors.

Compilation Errors

You have the following:

FD  IN-FILE
    DATA RECORD IS INPUT-RECORD
    LABEL RECORDS ARE STANDARD
    VALUE OF FILE-ID IS "C:\MYCOBOL\COBOL\Dane.TXT".
01  INPUT-REC.
    05 ID-C         PIC 9(5).
    05 NAME         PIC X(15).
    05 ADDRESS      PIC X(8).
    05 NIP          PIC 9(10).

In one place, you say INPUT-RECORD. When you define the record, you call it INPUT-REC. Fix one or the other.

I don't see what's wrong with SWITCHES. It might be a COBOL reserved word, so change it to WS-SWITCHES.

Finally, remove the END-READ from the two READ statements. I suggest putting the READ statement in its own paragraph, and performing it as the priming read and the loop read.

Upvotes: 3

Related Questions