You are here: Home > Knowledge Refreshers

KR editions 102 to 103

KR- 102 (Blocking - I)

Hi everyone,

KR triggered by Elan.

We've heard that BLKSIZE = n times LRECL (for a simple FB sequential file). We've also heard of FB (which stands for fixed blocked).
So what is blocking? 
It's a method by which the number of I/O operations (i.e. the physical reads and writes to a storage device can be reduced). 
When the OS reads a file, it'll read a block of data at a time. Within one block if we have only one record, then to read 10 records the OS has to read physically 10 times (note: we're not referring to the READ statement that is used in cobol here; we're referring to the low level reading of a file - which involves I/O device access).

But what is one record? 
A record is a logical grouping of data (if record length is 80 bytes then Byte number 1 to 80 is the first record, 81 to 160 is the second record and so on). In this case LRECL=80 and BLKSIZE=80 (i.e. one record within one block). A group of records form a file.

In COBOL, to read a file, we would say:
This read statement expects to read one record from test-file. But our COBOL code cannot directly read the file (it can't access the dasd directly; it has to go through the OS). So the OS will read one block and this block will contain one record (since BLKSIZE=LRECL=80). In programs we usually loop through a file (i.e. read records one by one until end of file). 
Thus for each cobol read statement the OS has to perform an I/O read operation to get the record. 100 records means 100 I/O reads.

To reduce I/O operations it is better to have more records within a single block (say ten records)- in this case LRECL=80 and BLKSIZE=800. Now when the OS reads a block, it actually reads 10 records in one shot and stores them in its buffer. 
So only for every 11th record does the OS need to physically read from the file. Now 100 records means only 10 I/O reads.
We'll summarize the process in the next edition.
Food for thought: What's the significance of the BLOCK CONTAINS xx RECORDS statement used in cobol in the FD section? And why should we worry about the number of I/O reads?

That's all for this edition,

KR-103 (Blocking II)

Hi everyone,

Continuing with blocking.....

  • Let's run through the process again with respect to a cobol code. Let's say our file (a sequential file) has LRECL=80 and BLKSIZE=800 
  • In our COBOL code we have a loop which reads through the entire file one record at a time. The read statement is: READ TEST-FILE INTO WS-STRUCTURE
  • The first time this statement is encountered the OS will read one block of data (i.e. 10 records into its buffer). But it'll pass only one record to our cobol code. 
  • The second time in the loop, the OS will give our code the second record by taking it from the buffer (it doesn't need to access the physical device to read the second record). 
  • Only on the 11th time will it have to read a block again.

So the number of I/O operations is reduced (I/O operations consume a lot of time when comopared to CPU processing speed- so reducing I/O operation helps improve performance; or one might say that blocking helps reduce I/O cost).

  • Next question: in the FD section we specify BLOCK CONTAINS xx RECORDS. What does this signify? 
  • It's an optional clause and it really won't be of significance in mainframes. Here the OS takes care of the blocking factor (which is specified as a property of the dataset). So this won't alter any functionality.

Did you know that in option 3.2 when allocating a dataset if you were to specify the block-size as 0, the OS would use an optimal block size.
That's all for this edition; suggestions for topics and KRs welcome

Go back to the main contents page