0% found this document useful (0 votes)
3 views3 pages

Sequential File Insert Explanation

The document explains how to add a record to a sequential file, emphasizing the need to read the old file, create a new one, and insert the new record in the correct order. It provides a step-by-step pseudocode breakdown for the process, including file declarations, opening files, inputting new records, comparing existing records, and final cleanup. It also notes that the append mode is only suitable for serial files, not sequential ones.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Sequential File Insert Explanation

The document explains how to add a record to a sequential file, emphasizing the need to read the old file, create a new one, and insert the new record in the correct order. It provides a step-by-step pseudocode breakdown for the process, including file declarations, opening files, inputting new records, comparing existing records, and final cleanup. It also notes that the append mode is only suitable for serial files, not sequential ones.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Adding a Record to a Sequential File –

Explained
In a sequential file, records are stored in order (usually by a key like registerNumber).
Unlike a serial file, you cannot just append new records at the end. You must:
1. Read the old file,
2. Create a new file,
3. Insert the new record in the correct place,
4. Copy the remaining records,
5. Replace the old file with the new one.

Step-by-Step Breakdown of the Pseudocode

1. Declarations

DECLARE studentRecord : TstudentRecord


DECLARE newStudentRecord : TstudentRecord
DECLARE studentFile : STRING
DECLARE newStudentFile : STRING
DECLARE recordAddedFlag : BOOLEAN

- Two record structures: one for existing, one for new.

- Two filenames: one original, one temporary.

- A boolean flag to check if the new record has been added.

2. Open/Create Files

CREATE newStudentFile
OPEN newStudentFile FOR WRITE
OPEN studentFile FOR READ

A new file is created for writing. The existing file is opened for reading.

3. Input the New Record

INPUT [Link]
INPUT [Link]
INPUT [Link]
INPUT [Link]
4. Read & Compare Existing Records

WHILE NOT recordAddedFlag OR BOF(studentFile)


GETRECORD, studentRecord
IF [Link] >
[Link] THEN
PUTRECORD studentRecord
ELSE
PUTRECORD newStudentRecord
recordAddedFlag ← TRUE

Inserts new record at the correct location based on register number.

5. Finish File Transfer

IF EOF(studentFile)
PUTRECORD newStudentRecord
ELSE
REPEAT
GETRECORD, studentRecord
PUTRECORD studentRecord
UNTIL EOF(studentFile)

6. Final Cleanup

CLOSEFILE studentFile
CLOSEFILE newStudentFile
DELETE studentFile
RENAME newStudentFile, studentFile

Replaces the old file with the newly updated file.

Table of Key Identifiers


Identifier Description

studentRecord Record read from student file

newStudentRecord New record to be written

studentFile Original student file name

newStudentFile Temporary new file name


Note: [Link] Append Mode (for Serial Files)
Use this code to open a file in append mode:
myFile = New FileStream("fileName", [Link])

This is suitable for serial files only. For sequential files, use the full read-copy-insert
method.

You might also like