Record Contains Clauses

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.

Syntax:

RECORD CONTAINS integer [TO integer] [BYTE] [CHARACTER]

Where “integer” is the number of bytes or characters in the record, and “TO integer” is used to specify the maximum number of bytes or characters. The optional “BYTE” or “CHARACTER” keyword is used to specify whether the record is in byte or character format.

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

Cobol




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


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

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

1. Fixed-length records:

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

Syntax:

 RECORD CONTAINS 10 BYTE

2. Dynamic-length records: 

The record length can change, but the maximum length is defined. For example, a record can contain up to 10 bytes of data, but it may only contain 5 bytes if that is all the data that is stored in the record. 

Syntax:

 RECORD CONTAINS 1 TO 10 BYTE

3. Variable-length records:

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

Syntax:

RECORD CONTAINS VARYING BYTE

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