Module 10: File processing
PROCESSING OF FILE: Step 4 of File Handling
Once file is opened using OPEN statement in required mode, files can be processed as per our requirement using the I-O statements such as READ, WRITE, REWRITE, START and DELETE.
Below provided is overview of each those statements and each of them will explained in detail in upcoming articles
- READ Statement:-
- READ is used to read a record from file
- At execution of a READ statement, only one record can be read. It also increments pointer to support successive reads.
- READ operation can be performed only when file is opened in INPUT or I-O mode.
- READ Statement is explained in detail here
- WRITE Statement:-
- It is used to insert logical record to an output or input/output file.
- When WRITE statement is coded without FROM clause, record to be inserted should be moved to record buffer and then perform WRITE operation. Once WRITE operation completes, record is vanished from record buffer.
- When WRITE is to be performed on file with sequential access mode, it should be opened in OUTPT or EXTEND mode
- When WRITE is to be performed on file with random or dynamic access mode, it should be opened in OUTPUT or I-O mode.
- WRITE Statement is explained in detail here
- REWRITE Statement:-
- REWRITE is used to update existing record. It overwrites the last record read.
- REWRITE can be performed only after opening file in I-O mode.
- REWRITE Statement is explained in detail here
- START Statement:-
- START statement is used to position the file pointer at a specific record location within indexed or relative file for subsequent sequential record retrieval
- This statement can be used only for Indexed and Relative files which are opned either in INPUT or I-O mode.
- Access mode of file must be sequential or dynamic. It cannot be coded for Random access
- It establish the current location in the cluster for a READ NEXT statement.
- It does not retrieve record; It only sets the current record pointer
- START Statement is explained in detail here
- DELETE Statement:-
- Used to logically remove records from indexed and relative files only
- It deletes the most recently read record
- To delete a record, the file should be opened in I-O mode
- DELETE Statement is explained in detail here