The RECORDS clause is a subclause of BLOCK CONTAINS used in File Description (FD) entries to specify the number of logical records that are grouped into each physical block. This blocking factor is crucial for optimizing I/O performance in COBOL file processing.
Multiple logical records are grouped into single physical blocks for efficient I/O operations.
The RECORDS clause follows specific syntax patterns within BLOCK CONTAINS specifications in File Description entries.
123456789101112131415161718* Basic RECORDS clause syntax BLOCK CONTAINS n RECORDS * Examples BLOCK CONTAINS 10 RECORDS BLOCK CONTAINS 50 RECORDS BLOCK CONTAINS 1 RECORD * Complete FD entry example FD CUSTOMER-FILE LABEL RECORDS ARE STANDARD BLOCK CONTAINS 20 RECORDS RECORD CONTAINS 80 CHARACTERS. 01 CUSTOMER-RECORD. 05 CUSTOMER-ID PIC 9(5). 05 CUSTOMER-NAME PIC X(30). 05 CUSTOMER-ADDRESS PIC X(35). 05 CUSTOMER-SALARY PIC 9(7)V99.
The RECORDS clause is always used with BLOCK CONTAINS to specify the blocking factor.
123456789101112131415161718* Blocking by character count BLOCK CONTAINS 800 CHARACTERS * Blocking by word count BLOCK CONTAINS 200 WORDS * Variable blocking (range) BLOCK CONTAINS 100 TO 200 CHARACTERS * Mixed specifications FD DATA-FILE BLOCK CONTAINS 10 RECORDS RECORD CONTAINS 80 CHARACTERS. * Character-based blocking FD TEXT-FILE BLOCK CONTAINS 1600 CHARACTERS RECORD CONTAINS 80 CHARACTERS.
RECORDS is one of several ways to specify blocking; CHARACTERS and WORDS are alternatives.
File Type | Typical Blocking Factor | Reasoning |
---|---|---|
Sequential Files | 10-50 records | Optimize for sequential processing |
Indexed Files | 5-20 records | Balance I/O efficiency with index performance |
Large Files | 50-100 records | Maximize I/O efficiency for bulk processing |
Small Files | 1-10 records | Minimize memory usage |
Tape Files | 20-100 records | Optimize for tape I/O characteristics |
The RECORDS clause significantly affects file processing performance through its impact on I/O operations and memory usage.
123456789* Scenario 1: Small blocking factor FD FILE-1 BLOCK CONTAINS 1 RECORD RECORD CONTAINS 100 CHARACTERS. * Scenario 2: Large blocking factor FD FILE-2 BLOCK CONTAINS 50 RECORDS RECORD CONTAINS 100 CHARACTERS.
Impact on a file with 10,000 records of 100 characters each:
Scenario | Block Size | Blocks Required | I/O Operations | Memory per I/O |
---|---|---|---|---|
Small blocking | 100 bytes | 10,000 | 10,000 | 100 bytes |
Large blocking | 5,000 bytes | 200 | 200 | 5,000 bytes |
Large blocking reduces I/O operations by 98% but requires 50x more memory per operation.
Storage Type | Optimal Blocking | Reasoning |
---|---|---|
Magnetic Tape | Large blocks (50-100 records) | Minimize tape stops and starts |
Hard Disk | Medium blocks (10-50 records) | Balance I/O efficiency with seek time |
SSD | Smaller blocks (5-20 records) | SSDs have different I/O characteristics |
Network Storage | Larger blocks (20-100 records) | Reduce network overhead |
These examples demonstrate how to use the RECORDS clause effectively in different file processing scenarios.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647IDENTIFICATION DIVISION. PROGRAM-ID. CUSTOMER-PROCESS. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT CUSTOMER-FILE ASSIGN TO "CUSTMAST.DAT" ORGANIZATION IS INDEXED ACCESS MODE IS SEQUENTIAL RECORD KEY IS CUSTOMER-ID FILE STATUS IS CUSTOMER-STATUS. DATA DIVISION. FILE SECTION. FD CUSTOMER-FILE LABEL RECORDS ARE STANDARD BLOCK CONTAINS 25 RECORDS RECORD CONTAINS 100 CHARACTERS. 01 CUSTOMER-RECORD. 05 CUSTOMER-ID PIC 9(5). 05 CUSTOMER-NAME PIC X(30). 05 CUSTOMER-ADDRESS PIC X(50). 05 CUSTOMER-STATUS PIC X. 05 FILLER PIC X(14). WORKING-STORAGE SECTION. 01 CUSTOMER-STATUS PIC XX. 01 RECORD-COUNT PIC 9(6) VALUE ZERO. 01 EOF-FLAG PIC X VALUE 'N'. 88 END-OF-FILE VALUE 'Y'. PROCEDURE DIVISION. MAIN-PROCESS. OPEN INPUT CUSTOMER-FILE PERFORM READ-CUSTOMERS UNTIL END-OF-FILE CLOSE CUSTOMER-FILE DISPLAY "Total records processed: " RECORD-COUNT STOP RUN. READ-CUSTOMERS. READ CUSTOMER-FILE AT END MOVE 'Y' TO EOF-FLAG NOT AT END ADD 1 TO RECORD-COUNT PERFORM PROCESS-CUSTOMER END-READ.
This example uses BLOCK CONTAINS 25 RECORDS for efficient sequential processing of customer data.
12345678910111213141516FD TRANSACTION-FILE LABEL RECORDS ARE STANDARD BLOCK CONTAINS 50 RECORDS RECORD CONTAINS 80 CHARACTERS. 01 TRANSACTION-RECORD. 05 TRANS-DATE PIC 9(8). 05 TRANS-TIME PIC 9(6). 05 TRANS-TYPE PIC X. 05 TRANS-AMOUNT PIC 9(7)V99. 05 ACCOUNT-NUMBER PIC 9(10). 05 TRANS-DESCRIPTION PIC X(40). 05 FILLER PIC X(6). * High-volume transaction processing benefits from larger blocking * 50 records per block optimizes I/O for bulk processing * Each block contains 4,000 characters (50 × 80)
High-volume transaction files use larger blocking factors for maximum I/O efficiency.
1234567891011FD REPORT-FILE LABEL RECORDS ARE STANDARD BLOCK CONTAINS 10 RECORDS RECORD CONTAINS 132 CHARACTERS. 01 REPORT-RECORD. 05 REPORT-LINE PIC X(132). * Report files use smaller blocking for flexibility * 10 records per block allows for efficient line-by-line processing * Each block contains 1,320 characters (10 × 132) * Suitable for both sequential and random access patterns
Report files use moderate blocking factors to balance I/O efficiency with processing flexibility.
Following these best practices ensures optimal use of the RECORDS clause for file processing performance.
Pitfall | Problem | Solution |
---|---|---|
Too small blocking | Excessive I/O operations | Use at least 5-10 records per block |
Too large blocking | Memory pressure, poor random access | Limit to 50-100 records for most files |
Ignoring storage medium | Suboptimal performance | Match blocking to storage characteristics |
No performance testing | Unknown optimal values | Test with realistic data volumes |
Inconsistent blocking | Maintenance complexity | Standardize blocking across similar files |
Usage | Syntax | Example |
---|---|---|
Basic blocking | BLOCK CONTAINS n RECORDS | BLOCK CONTAINS 10 RECORDS |
With RECORD CONTAINS | BLOCK CONTAINS n RECORDS RECORD CONTAINS m CHARACTERS | BLOCK CONTAINS 20 RECORDS RECORD CONTAINS 80 CHARACTERS |
Character blocking | BLOCK CONTAINS n CHARACTERS | BLOCK CONTAINS 800 CHARACTERS |
Word blocking | BLOCK CONTAINS n WORDS | BLOCK CONTAINS 200 WORDS |
Variable blocking | BLOCK CONTAINS n TO m CHARACTERS | BLOCK CONTAINS 100 TO 200 CHARACTERS |
1. What is the primary purpose of the RECORDS clause in COBOL?
2. In which context is the RECORDS clause most commonly used?
3. What is the relationship between RECORDS and BLOCK CONTAINS?
4. What happens if you specify BLOCK CONTAINS 10 RECORDS?
5. Which of the following is NOT a valid RECORDS specification?
Understanding the BLOCK CONTAINS clause for file blocking.
Using RECORD CONTAINS for record size specification.
Complete guide to File Description entries.
Understanding different file organizations.
Working with sequential files in COBOL.