Kent Wong
Kent Wong

Reputation: 143

Read data from file without using perform until and at end

I am trying to read data using Cobol with following the restriction

NOT allowed to use :

AT END clause

PERFORM-UNTIL

IF-ELSE

Switch case statement

Iteration Statement

   002-READ.
        READ d-attendance
        IF (?????)
           perform  002-READ
        END-IF.

I am trying to simulate a loop with code above but i don't know how I should write the IF statement, is there any way to detect EOF without using AT END?

Upvotes: 2

Views: 316

Answers (1)

Huzo
Huzo

Reputation: 1692

When you first define your file under file-control, you can define it like this:

select my-file
    assign to 'ifile.txt'
    organization is line sequential
    file status is fs. 

now, fs variable's value changes when you read from the file. For instance, when no errors are found, fs takes the value 00. More information can be found here.

If you are not allowed to use such statements that you have listed, then you can call your function that reads a line recursively until fs is not equal to 00.

Upvotes: 3

Related Questions