File Handling Verbs in COBOL Language
File handling in COBOL involves using specific file handling verbs to interact with external files. Th
ese 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
SELECTstatement 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
OPENverb 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
CLOSEverb 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
READverb 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
WRITEverb 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
REWRITEverb 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
DELETEverb is used to remove a record from an indexed or relative file.
DELETE My-File
- START: The
STARTverb 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
CLOSEverb 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
REWRITEverb 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
DELETEverb is used to remove a record from an indexed or relative file.DELETE My-File - START: The
STARTverb 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 - Embedded Systems & VLSI Lab
Subscribe to get the latest posts sent to your email.



