With sequential files, each element (usually a record) must be processed in turn. If you want to process a particular record, you must read every record in the file in turn until you get to the one you want.
Sequential files are appropriate when you want to process most (or all) of the records in a file every time you run your program.
The mechanics of using sequential files are very similar to the mechanics of using text files:
Unlike text files, sequential files cannot be created or viewed with a text editor. They must be created and displayed under program control.
An example program demonstrates all of the things listed above and described in detail below.
To use sequential files, you need a WITH statement that imports the SEQUENTIAL_IO library.
You must define the element type first, and can then instantiate the SEQUENTIAL_IO library. This creates an I/O library of routines for manipulating a sequential file of that type of element.
example:
with SEQUENTIAL_IO; procedure demo is ... type details is record name : string (1..30); address : string (1..80); age : natural; end record; package details_io is new SEQUENTIAL_IO (details);
file_variable : package.FILE_TYPE;
Example:
details_file : details_io.FILE_TYPE;
OPEN (olddetails, IN_FILE, "details.dat"); CREATE (newdetails, OUT_FILE, "newdetails.dat");
SEQUENTIAL_IO provides procedures for I/O:
Note:
Example:
while not END_OF_FILE (olddetails) loop READ (olddetails, one_person); ... WRITE (newdetails, one_person); end loop;
You cannot use a text editor to create or display a structured file.
Use specially-written programs.