Files File organisation and usage A record is a group of logically related fields A file is a group...

24
Files File organisation and usage A record is a group of logically related fields A file is a group of logically related records Files are used to store Large volumes Volatile information Files are stored on secondary storage

Transcript of Files File organisation and usage A record is a group of logically related fields A file is a group...

Page 1: Files  File organisation and usage A record is a group of logically related fields A file is a group of logically related records Files are used to store.

Files

File organisation and usage A record is a group of logically related fields A file is a group of logically related records Files are used to store

Large volumesVolatile information

Files are stored on secondary storage

Page 2: Files  File organisation and usage A record is a group of logically related fields A file is a group of logically related records Files are used to store.

Files

File categories Serial files Indexed sequential files Relative files

Page 3: Files  File organisation and usage A record is a group of logically related fields A file is a group of logically related records Files are used to store.

Serial Files

Text files Program files Report files Work files Transaction files Sequential files Different record formats possible

Page 4: Files  File organisation and usage A record is a group of logically related fields A file is a group of logically related records Files are used to store.

Characteristics of Serial Files

Records written consecutively More than one record format Stored on serial devices or DASDs (Direct

Access Storage Devices) Used for sorting Can be used in batch mode Sequential access quicker

Page 5: Files  File organisation and usage A record is a group of logically related fields A file is a group of logically related records Files are used to store.

Suitable Subjects for Serial Files

No direct access requirement Large volumes of information Record order unimportant Different record types No updating requirement

Page 6: Files  File organisation and usage A record is a group of logically related fields A file is a group of logically related records Files are used to store.

Using Sequential Files

Preparation Source - key to tape, key to disk, optical

scanners, voice recognisers Verification on communication and values

required May be sorted or merged

Page 7: Files  File organisation and usage A record is a group of logically related fields A file is a group of logically related records Files are used to store.

Using Sequential Files

Prepare the data Copy the file to offline backup Copy the file locally Check fields Merge multiple files Sort

Page 8: Files  File organisation and usage A record is a group of logically related fields A file is a group of logically related records Files are used to store.

Using Sequential Files

Declare the file to the program To read:

Open the file for input to the program Read the first record Check to see if the read failed due to end-of-file While not end-of-file

Process the record Read the next record

Close the file

Page 9: Files  File organisation and usage A record is a group of logically related fields A file is a group of logically related records Files are used to store.

Indexed Sequential File Characteristics

File management system looks after indexing

Records are accessed directly or sequentially Each record has one or more key fields Overuse of indexing is inefficient Very good multi-user capabilities

Page 10: Files  File organisation and usage A record is a group of logically related fields A file is a group of logically related records Files are used to store.

Indexed Sequential File Ideal Subjects

Medium to large amount of data Data filed mainly by one key Regular sequential and direct access Possible skip sequential access Low volatility and growth Low alternate key access requirement

Page 11: Files  File organisation and usage A record is a group of logically related fields A file is a group of logically related records Files are used to store.

Using Indexed Sequential Files

Declaring File and device name Organisation (indexed) Primary key Alternate keys

Creation Writes using keys

Page 12: Files  File organisation and usage A record is a group of logically related fields A file is a group of logically related records Files are used to store.

Retrieval From Indexed Sequential Files

Direct access: Give key value Read, allowing for no record, or lock

Direct and sequential Read next record, allowing for end of file or lock

Page 13: Files  File organisation and usage A record is a group of logically related fields A file is a group of logically related records Files are used to store.

Retrieval From Indexed Sequential Files

Sequential Specify start of range and key Loop to

Read next record, allowing for end-of-file and lock

Check for end of range or file

Page 14: Files  File organisation and usage A record is a group of logically related fields A file is a group of logically related records Files are used to store.

Updating Indexed Sequential Files

Change non-primary key values Read record directly with lock Change non-primary key values Rewrite record Unlock

Page 15: Files  File organisation and usage A record is a group of logically related fields A file is a group of logically related records Files are used to store.

Updating Indexed Sequential Files

Changing primary key value Read record directly with lock Check for new record viability Copy record details Write new record with lock Delete old record Release locks

Page 16: Files  File organisation and usage A record is a group of logically related fields A file is a group of logically related records Files are used to store.

Deleting From IS Files

Read record with lock VERIFY that deletion is required Delete record Release locks

Page 17: Files  File organisation and usage A record is a group of logically related fields A file is a group of logically related records Files are used to store.

Direct Access or Relative Files

Records can be accessed directly, according to the number of the record within the file

Each record has a key, which is it’s relative address from the start of the file

This is suitable for only a small number of records

Page 18: Files  File organisation and usage A record is a group of logically related fields A file is a group of logically related records Files are used to store.

Direct Access or Relative Files

All key values must be used Very easy to use (using relative addressing) Hashing functions can be used (see

algorithms course)

Page 19: Files  File organisation and usage A record is a group of logically related fields A file is a group of logically related records Files are used to store.

Using Relative Files

File is declared using file name and storage device

Organisation is relative An independent variable holds the key The record format is declared

Page 20: Files  File organisation and usage A record is a group of logically related fields A file is a group of logically related records Files are used to store.

Using Relative Files

The file is opened for input, output or updating

Records can be read, added, amended using direct access

Records can be read sequentially from a pre-set point in the file

The file is closed

Page 21: Files  File organisation and usage A record is a group of logically related fields A file is a group of logically related records Files are used to store.

Using Relative Files

Creation Addressing method must be implemented to

position records Insertion of records uses direct access

Page 22: Files  File organisation and usage A record is a group of logically related fields A file is a group of logically related records Files are used to store.

Using Relative Files

Retrieval Sequential access if no hashing Retries may be necessary if hashing being used Retries may be necessary if multi-user file, because of

locking Updates

Direct access mode Deletion causes gaps Record / file locking must be implemented

Page 23: Files  File organisation and usage A record is a group of logically related fields A file is a group of logically related records Files are used to store.

Relative Files

Select Expend-file assign "Expend.dat"

organization is relative

access mode is random

relative key is month-number.

Working-Storage Section.

01 month-number pic 99.

Page 24: Files  File organisation and usage A record is a group of logically related fields A file is a group of logically related records Files are used to store.

Procedure division

Open I-O Expend-file.

Move L-month-in to month-number.

Read Expend-file

invalid key

display "month not found for " L-month-in

not invalid key

move fields to record

rewrite expend-record

invalid key

display "Error rewriting ... "

end-rewrite

end-read

close expend-file.