sequential files

28
Sequential Files Sequential Files Chapter 13 Chapter 13

Upload: nero

Post on 11-Feb-2016

65 views

Category:

Documents


1 download

DESCRIPTION

Sequential Files. Chapter 13. Master Files. Set of files used to store companies data in areas like payroll, inventory Usually processed by batch processing Typically stored on magnetic disk Disks can store billions of characters Disk drives read, write data quickly - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Sequential Files

Sequential FilesSequential Files

Chapter 13Chapter 13

Page 2: Sequential Files

Master FilesMaster Files Set of files used to store companies data in Set of files used to store companies data in

areas like payroll, inventoryareas like payroll, inventory Usually processed by batch processingUsually processed by batch processing Typically stored on magnetic diskTypically stored on magnetic disk

Disks can store billions of charactersDisks can store billions of characters Disk drives read, write data quicklyDisk drives read, write data quickly Disk records can be any sizeDisk records can be any size

Page 3: Sequential Files

Sequential FilesSequential Files Records always read in sequenceRecords always read in sequence Read first record, process it, then read second Read first record, process it, then read second

record, process it and so onrecord, process it and so on Payroll records in order by employee number may Payroll records in order by employee number may

be processed in sequence for updating or printing be processed in sequence for updating or printing reportsreports

Page 4: Sequential Files

Sequential FilesSequential Files May be sorted into any sequence using any May be sorted into any sequence using any

field in recordfield in record To distribute checks more easily, records may be To distribute checks more easily, records may be

sorted by department sorted by department Sequential processing then used to print Sequential processing then used to print

checks, reading first record, then second, etc.checks, reading first record, then second, etc.

Page 5: Sequential Files

Master File ProceduresMaster File Procedures

Typical procedures for sequential processing in Typical procedures for sequential processing in batch mode are:batch mode are:

Designing Master FileDesigning Master File Creating Master FileCreating Master File Creating Transaction FileCreating Transaction File Updating Master FileUpdating Master File Reporting from Master FileReporting from Master File

Page 6: Sequential Files

Designing a Master FileDesigning a Master File Place key fields that uniquely identify record Place key fields that uniquely identify record

at beginning of recordat beginning of record If possible, choose numeric key fieldsIf possible, choose numeric key fields Secondary fields after primary key fieldsSecondary fields after primary key fields Remaining fields appear in order of Remaining fields appear in order of

importanceimportance

Page 7: Sequential Files

Designing a Master FileDesigning a Master File Choose field size large enough to Choose field size large enough to

accommodate data stored in itaccommodate data stored in it Use coded fields where possible to save spaceUse coded fields where possible to save space Be sure all date fields include four-digit yearBe sure all date fields include four-digit year

Page 8: Sequential Files

Creating a Master FileCreating a Master File Original master file data entered interactively, Original master file data entered interactively,

stored on disk filestored on disk file Ensure data integrity by using data validation Ensure data integrity by using data validation

techniques to minimize risk or errorstechniques to minimize risk or errors Control listing or audit trail produced to show Control listing or audit trail produced to show

data stored in new master file and control data stored in new master file and control totalstotals

Page 9: Sequential Files

Creating a Transaction FileCreating a Transaction File Changes to master file made with separate Changes to master file made with separate

procedureprocedure Change records stored in file called transaction Change records stored in file called transaction

filefile

Page 10: Sequential Files

Updating a Master FileUpdating a Master File Updating is process of making master file Updating is process of making master file

currentcurrent Update master file by incorporating changes Update master file by incorporating changes

from transaction recordsfrom transaction records

Page 11: Sequential Files

Reporting from a Master FileReporting from a Master File Scheduled reportsScheduled reports prepared on regular basis prepared on regular basis

from data stored in master filefrom data stored in master file Sales reports, customer bills, checks, etc.Sales reports, customer bills, checks, etc. Use detail, exception and group printing Use detail, exception and group printing

techniquestechniques On demand reportsOn demand reports produced as need arises produced as need arises

May be in report form or displayed on screenMay be in report form or displayed on screen

Page 12: Sequential Files

Sequential File UpdatingSequential File Updating

Two input filesTwo input files Input Master File (Old-Master)Input Master File (Old-Master)

Current through previous updating periodCurrent through previous updating period Does not contain changes Does not contain changes sincesince previous update previous update

Input Transaction File (Trans-File)Input Transaction File (Trans-File) Contains changes since previous update to be Contains changes since previous update to be

applied to Old-Masterapplied to Old-Master

Page 13: Sequential Files

Sequential File UpdatingSequential File Updating

Two output filesTwo output files Output Master File (New-Master)Output Master File (New-Master)

Integrates data from Old-Master with all of Integrates data from Old-Master with all of changes from Trans-Filechanges from Trans-File

Will become Old-Master for next updateWill become Old-Master for next update Control Listing or Audit TrailControl Listing or Audit Trail

Print file showing changes made to master file, Print file showing changes made to master file, errors during processing and control totalserrors during processing and control totals

Page 14: Sequential Files

SequentialMaster File

Update

TransactionFile

UpdatedMaster

File

MasterFile

UpdateActivityReport

Sequential File Update

Page 15: Sequential Files

Ordering of RecordsOrdering of Records Records in Old-Master and Trans-File must be Records in Old-Master and Trans-File must be

in order by same key fieldin order by same key field Compare key fields to determine if given Compare key fields to determine if given

master record is to be updatedmaster record is to be updated

Page 16: Sequential Files

Master FileMaster File1223 ………..1223 ………..1277 ………..1277 ………..1456 ………..1456 ………..2835 ………..2835 ………..2910 ………..2910 ………..3006 ………..3006 ………..3100 ………..3100 ………..3143 ………..3143 ………..4372 ………..4372 ………..^z^z

Transaction FileTransaction File1235 ……………………..A1235 ……………………..A1273 ……………………..C1273 ……………………..C1456 ……………………..C1456 ……………………..C1543 ……………………..D1543 ……………………..D1678 ……………………..B1678 ……………………..B2910 ……………………..C2910 ……………………..C3006 ……………………..D3006 ……………………..D3098 ……………………..C3098 ……………………..C3099 ……………………..D3099 ……………………..D^z^z

1223 …………………………1235 …………………………1277 …………………………1456 …………………………2835 …………………………2910 …………………………3100 …………………………3143 …………………………4372 …………………………^z

New Master File

Page 17: Sequential Files

Sequential Update ProcedureSequential Update Procedure Initially, record read from both Old-Master Initially, record read from both Old-Master

and Trans-Fileand Trans-File Comparison of M-Acct-No and T-Acct-No Comparison of M-Acct-No and T-Acct-No

determines next stepdetermines next step

Page 18: Sequential Files

1) T-Acct-No = M-Acct-No1) T-Acct-No = M-Acct-No

Means transaction record exists with same Means transaction record exists with same account number as master recordaccount number as master record

Perform regular update, adding Trans-File Perform regular update, adding Trans-File amount to Old-Master amount, storing result amount to Old-Master amount, storing result in New-Master fieldin New-Master field

Read next record from Trans-FileRead next record from Trans-File

Page 19: Sequential Files

2) T-Acct-No > M-Acct-No2) T-Acct-No > M-Acct-No

Means master record exists for which there is Means master record exists for which there is no corresponding transaction recordno corresponding transaction record

Write record from Old-Master to New-Master Write record from Old-Master to New-Master as is, since no changes need to be made to itas is, since no changes need to be made to it

Read next record from Old-MasterRead next record from Old-Master

Page 20: Sequential Files

3) T-Acct-No < M-Acct-No3) T-Acct-No < M-Acct-No

Means transaction record exists for which Means transaction record exists for which there is no corresponding master recordthere is no corresponding master record

Two ways to process this transactionTwo ways to process this transaction Create record in New-Master file for this Create record in New-Master file for this

transactiontransaction May assume that T-Acct-No is invalid since no May assume that T-Acct-No is invalid since no

match found in Old-Master file and treat as error match found in Old-Master file and treat as error conditioncondition

Page 21: Sequential Files

Use of HIGH-VALUESUse of HIGH-VALUES Refers to largest value in computer's collating Refers to largest value in computer's collating

sequence sequence Used so all records from both Old-Master and Used so all records from both Old-Master and

Trans-File are processedTrans-File are processed May reach end of Old-Master file before May reach end of Old-Master file before

reaching end of Trans-File or vice versareaching end of Trans-File or vice versa

Page 22: Sequential Files

Use of HIGH-VALUESUse of HIGH-VALUES When last record read from Old-Master, M-When last record read from Old-Master, M-

Acct-No set to HIGH-VALUESAcct-No set to HIGH-VALUES For all remaining transaction records T-Acct-No < For all remaining transaction records T-Acct-No <

M-Acct-No M-Acct-No Processed as new accounts and added to New-Processed as new accounts and added to New-

MasterMaster

Page 23: Sequential Files

Use of HIGH-VALUESUse of HIGH-VALUES When last record read from Trans-File, T-When last record read from Trans-File, T-

Acct-No set to HIGH-VALUESAcct-No set to HIGH-VALUES For all remaining Old-Master records T-Acct-No For all remaining Old-Master records T-Acct-No

> M-Acct-No > M-Acct-No Old-Master records added to New-Master without Old-Master records added to New-Master without

changeschanges

Page 24: Sequential Files

Use of HIGH-VALUESUse of HIGH-VALUES Loop to process records ends only when both Loop to process records ends only when both

account numbers equal HIGH-VALUESaccount numbers equal HIGH-VALUES May be used only with fields defined as May be used only with fields defined as

alphanumericalphanumeric Define account number fields with PIC of Xs even Define account number fields with PIC of Xs even

though fields contain numbersthough fields contain numbers

Page 25: Sequential Files

Validity Checking in UpdatingValidity Checking in Updating Code field may be added to each transaction Code field may be added to each transaction

record to indicate whether transaction isrecord to indicate whether transaction is New account to be addedNew account to be added Update to existing accountUpdate to existing account Deletion of existing accountDeletion of existing account

Comparison of keys and transaction code type Comparison of keys and transaction code type enable program to detect other update errorsenable program to detect other update errors

Page 26: Sequential Files

Updating Master Disk in PlaceUpdating Master Disk in Place May read a master disk record, make changes May read a master disk record, make changes

directly to same record, and rewrite it or update it directly to same record, and rewrite it or update it in placein place

Only two files neededOnly two files needed Master-FileMaster-File OPEN as I-OOPEN as I-O Trans-FileTrans-File OPEN as INPUTOPEN as INPUT

Use REWRITE statement to replace master disk Use REWRITE statement to replace master disk record, currently in storage, that was accessed by record, currently in storage, that was accessed by preceding READpreceding READ

Page 27: Sequential Files

Updating Master Disk in PlaceUpdating Master Disk in Place To delete a record, establish each record with To delete a record, establish each record with

an activity code fieldan activity code field For example, Code-X = 1 if record is active, or 2 if For example, Code-X = 1 if record is active, or 2 if

record is inactiverecord is inactive All master records initially active (1 in Code-All master records initially active (1 in Code-

X)X) Master record deactivated by changing activity Master record deactivated by changing activity

code to 2code to 2

Page 28: Sequential Files

Updating Master Disk in PlaceUpdating Master Disk in Place New records cannot be added in sequence New records cannot be added in sequence

when file open for I-Owhen file open for I-O Can add records at end of file by opening file Can add records at end of file by opening file

in EXTEND modein EXTEND modeOPENOPEN EXTENDEXTEND file-name file-name

Disk automatically positioned at end of file, Disk automatically positioned at end of file, immediately after last recordimmediately after last record

Sort file after records added to arrange them in Sort file after records added to arrange them in sequencesequence