File Handling Verbs in COBOL Language
File handling in COBOL involves using specific file handling verbs to interact with external files. These verbs allow COBOL programs
to perform operations like opening, reading, writing, closing, and deleting files. Here are some of the key file handling verbs in COBOL:- SELECT: The
SELECT
statement is used to define the structure and attributes of a file. It specifies the file name, the file type (e.g., SEQUENTIAL, INDEXED, RELATIVE), the access mode (e.g., SEQUENTIAL, RANDOM, DYNAMIC), and other file attributes.
SELECT My-File
ASSIGN TO "data.dat"
ORGANIZATION IS SEQUENTIAL
ACCESS MODE IS RANDOM.
- OPEN: The
OPEN
verb is used to open a file for input, output, or both. It prepares the file for subsequent read or write operations.
OPEN INPUT My-File
- CLOSE: The
CLOSE
verb is used to close a previously opened file. This ensures that any buffered data is written to the file and that resources are released.
CLOSE My-File
- READ: The
READ
verb is used to read records from a file. It allows you to retrieve data from the file, one record at a time.
READ My-File
AT END
DISPLAY "End of file."
NOT AT END
DISPLAY "Data read from file: " data
END-READ
- WRITE: The
WRITE
verb is used to write records to a file. It allows you to add or update data in the file.
WRITE My-File
FROM record-data
- REWRITE: The
REWRITE
verb is used to update an existing record in an indexed or relative file. It replaces the current record with new data.
REWRITE My-File
FROM updated-record-data
- DELETE: The
DELETE
verb is used to remove a record from an indexed or relative file.
DELETE My-File
- START: The
START
verb is used to position the file’s read or write pointer at a specific location based on a key value. It is commonly used in indexed file processing.
START My-File
KEY IS key-value
- CLOSE: The
CLOSE
verb is used to close a previously opened file. This ensures that any buffered data is written to the file and that resources are released.
CLOSE My-File
- REWRITE: The
REWRITE
verb is used to update an existing record in an indexed or relative file. It replaces the current record with new data.REWRITE My-File FROM updated-record-data
- DELETE: The
DELETE
verb is used to remove a record from an indexed or relative file.DELETE My-File
- START: The
START
verb is used to position the file’s read or write pointer at a specific location based on a key value. It is commonly used in indexed file processing.START My-File KEY IS key-value
Discover more from PiEmbSysTech
Subscribe to get the latest posts sent to your email.