UNIHIVE

Study Hub UNIPORT CSC 283

CSC 283 · Information Systems and File Structures

Updating a sequential master file

The classic batch update: master and transaction files matched in key order, with additions, amendments, deletions and errors, plus a worked run.

Our notes

2 min read

The files

  • Master file: the main, fairly permanent file (student records, account balances), in key order.
  • Transaction file: the changes for this run (new registrations, payments, withdrawals), each with a key and a code: I (insert), A (amend), D (delete).
  • New master file: written by the run.
  • Error report: transactions that could not be applied.

The steps

  1. Validate transactions (correct format, valid codes, sensible values).
  2. Sort them into master key order.
  3. Match master and transaction records in one pass (the balance-line or match-merge method).

The matching logic

Read one master (M) and one transaction (T). Then repeat:

  • If M.key < T.key: no change for this master: copy M to the new master; read the next M.
  • If M.key = T.key:
  • A: apply the change to M (keep it in memory; more amendments may follow); read next T.
  • D: drop M (do not copy it); read next M and next T.
  • I: error (record already exists); read next T.
  • If M.key > T.key:
  • I: write the new record to the new master; read next T.
  • A or D: error (no such record); read next T.

Use a "high value" key (larger than any real key) at the end of each file so the loop finishes cleanly.

Worked example

Master keys: 101, 104, 107, 110.
Transactions (sorted): 102 I, 104 A, 107 D, 108 A, 110 A, 112 I.

StepMTAction
1101102 I101 < 102: copy 101
2104102 I104 > 102, insert: write 102
3104104 Aequal, amend 104
4104107 D104 < 107: copy amended 104
5107107 Dequal, delete: skip 107
6110108 A110 > 108, amend: error "108 not found"
7110110 Aequal, amend 110
8110112 I110 < 112: copy amended 110
9end112 Iinsert: write 112

New master: 101, 102, 104 (amended), 110 (amended), 112. Error report: 108.

Why the old master is kept

The run never changes the old master, so if anything goes wrong the run can be repeated from the old master and the transactions. This is the basis of the grandfather-father-son backup system (see file maintenance).

Exams usually ask

  • Describe the files used in a sequential update and the role of each.
  • Write or trace the matching algorithm for given master and transaction keys.
  • List the errors that the update must report.

Common mistake

Writing the master record as soon as one amendment is applied. Several amendments for the same key may follow; write the record only when the next transaction key is higher.

Written by the UniHive team in our own words. Spotted a mistake? Tell us on WhatsApp.

No reading links here yet

Our team adds free books, videos and practice for each topic, and opens every link before it goes up.

All CSC 283 topics

Report

Sign in to report this. It is free.

Is this your work (a lecturer, author or publisher)? Ask us to take it down.