BLOCK CONTAINS Clauses

The BLOCK CONTAINS clause is used in the FILE SECTION of the COBOL program to specify the block size of a file. It is used to define the number of records that can be stored in a block, as well as the type of block format that is used.

Syntax:

BLOCK CONTAINS integer [RECORD] [TO integer] [RECORD]

where “integer” is the number of records in the block and “TO integer” is used to specify the maximum number of records. The optional “RECORD” keyword is used to specify that the block size is in terms of records.

Here’s an example of how the BLOCK CONTAINS clause could be used in a COBOL program:

Cobol




FD CUSTOMER-FILE
BLOCK CONTAINS 10 RECORD
RECORD CONTAINS 80 CHARACTERS
DATA RECORD IS CUSTOMER-RECORD.


This example defines a file called “CUSTOMER-FILE” with a block format that contains 10 records. Each record contains 80 characters and the record layout is defined in the “CUSTOMER-RECORD” data record.

Note: The BLOCK CONTAINS clause is used in conjunction with the RECORD CONTAINS clause, the BLOCK CONTAINS defines how many records are in a block and the RECORD CONTAINS defines the layout of each record.

There are three main types of block format that can be specified using the BLOCK CONTAINS clause:

1. Fixed-length blocks:

The block size is fixed and does not change. For example, if a block contains 10 records, it will always be 10 records long, regardless of the amount of data stored in the block.

Syntax:

 BLOCK CONTAINS 10 RECORD

2. Dynamic-length blocks:

The block size can change, but the maximum size is defined. For example, a block can contain up to 10 records, but it may only contain 5 records if that is all the data that is stored in the block.

Syntax:

BLOCK CONTAINS 1 TO 10 RECORD

3.Variable-length blocks: 

The block size can change, and there is no maximum size defined. For example, a block can contain any number of records. This format is often used for variable-length fields such as text or variable-length elements. 

Syntax: 

BLOCK CONTAINS VARYING RECORD

File Section in COBOL

COBOL is a high-level programming language for business applications or business use. It was designed in 1959 by the Conference on Data Systems Language (CODASYL). It was primarily used in business, finance, and administration system for companies and governments. COBOL is still widely used in application deployment on mainframe computers.

File Selection

In COBOL, file selection is the process of identifying which records in a file should be processed or read. This is typically done using the SELECT and ASSIGN clauses in the FILE-CONTROL paragraph of the COBOL program.

The SELECT clause is used to specify the file that will be used in the program, and the ASSIGN clause is used to specify the device or file name where the file is stored.

For example, to select a file called “CUSTOMER” that is stored on a magnetic tape, the following code could be used:

Cobol




SELECT CUSTOMER-FILE 
ASSIGN TO TAPE


Additionally, the COBOL program can use the READ statement and a conditional statement to read only the records that meet certain conditions and skip the rest of the records.

For example, to read only the records of customers with a balance greater than zero:

Cobol




READ CUSTOMER-FILE
INTO CUSTOMER-RECORD
IF CUSTOMER-RECORD-BALANCE > 0
PERFORM PROCESS-CUSTOMER


Note: The file selection and reading methods may vary depending on the specific COBOL implementation and platform being used.

Similar Reads

Record Contains Clauses

...

BLOCK CONTAINS Clauses

...

RECORDING MODE Clause

The RECORD CONTAINS clause is used in the FILE SECTION of the COBOL program to specify the record layout of a file. It is used to define the size and position of each data field within a record, as well as the type of record format that is used....

Contact Us