Wildcat COBOL 0.1.13 Introduces Sequential File Support

It's that time again - a new version of the Wildcat COBOL Compiler for Mono and .NET is out. Version 0.1.13 introduces experimental support for reading sequential data files, and making use of level 88 data definitions. I'll explain these advances in some more detail...

Consider the following excerpt from the fileread.cbl program which is included in the version 0.1.13 ZIP file (click to enlarge):

example from fileread.cbl

This code opens a file, and reads the first line. This data is stored in the StudentFile record which has been declared in the FILE SECTION of the DATA DIVISION. The code then loops until EndOfStudentFile evaulates to be true. EndOfStudentFile was declared as a level 88 member of the StudentFile record. Level 88 is special in that it can be used to store and test for certain conditions. Here, it is used to indicate whether or not the end of the sequential data file has been reached.

Inside the loop, the DISPLAY statement prints out the values of some parts of the StudentFile record, then the next record is read from the file, until the end of the file has been reached. When the end is reached, EndOfStudentFile is set to true, and the loop exits.

The READ statement can have "AT END" and "NOT AT END" sections inside it, which specify code to execute when each of those conditions is true.

This diagram shows the logic the compiler uses when compiling READ statements:

The code used in this example is based on Introduction to Sequential Files from the University of Limerick.

No comments

Post a comment

What is eight added to three ?:
Name: URL:
Comment: