Chapter 5. File Handling

A typical modern computer language may not use files often. A programming book or manual may not even cover this topic. This makes sense, as many applications do not necessarily handle data processing.

But the situation is different with the mainframe. File handling is an essential part of the process. This goes back to the early days, when businesses wanted to find ways to replace the tedious approaches of using ledgers and 3 x 5-inch cards. The mainframe and COBOL were seen as a way to automate the back office.

To this end, various types of files are available. They include sequential, indexed, and relative. In this chapter, we’ll take a look at the first two and show how the COBOL language can use them. Relative files are not used much and therefore are not covered in this book.

Records and Files

A file for a mainframe is usually composed of a set of records, which is a group of related fields. An example of a record is a customer master file, which has fields for first name, last name, address, credit limit, and so on.

A mainframe initially reads the records into the real or central storage; this is similar to random access memory (RAM) for PCs. Even though the capacity is high, a file can easily exceed the storage limit. This is why a mainframe reads one or a small group of records at a time, so as not to overwhelm the real memory.

Typically, a record is fixed-length, each having the same number of characters. But in some cases, a dataset has variable-length ...

Get Modern Mainframe Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.