Sequential Files : Outline ! Overview ! Ordered vs. Unordered ! - - PowerPoint PPT Presentation

sequential files outline
SMART_READER_LITE
LIVE PREVIEW

Sequential Files : Outline ! Overview ! Ordered vs. Unordered ! - - PowerPoint PPT Presentation

Sequential Files : Outline ! Overview ! Ordered vs. Unordered ! Physical sequential Files ! Physical Linked Sequential Files ! COBOL rasitjutrakul Sequential Files " Logically the records are stored consecutively Physical sequential file


slide-1
SLIDE 1

rasitjutrakul

Sequential Files : Outline

! Overview ! Ordered vs. Unordered ! Physical sequential Files ! Physical Linked Sequential Files ! COBOL

slide-2
SLIDE 2

rasitjutrakul

Sequential Files "Logically the records are stored consecutively

– Physical sequential file – Physical linked sequential file

block 1 block 2 block 3 block n

...

block 1 block 1 block 2 block 2 block 3 block 3 block n block n

...

Batch and RetrieveAll Batch and RetrieveAll

slide-3
SLIDE 3

rasitjutrakul

Ordered and Unordered "Ordered sequential files

– the logical records are stored sequentially in increasing (or decreasing) order according to their primary key values.

"Unordered sequential files

– the logical records are stored no in any specific order.

slide-4
SLIDE 4

rasitjutrakul

Notations "Let S be a file

– NR : the number of logical records – BF : the blocking factor – NBLK : the number of blocks

"SL[operation, S] : search length "sba

: sequential block access

"rba

: random block access

slide-5
SLIDE 5

rasitjutrakul

Physical Sequential Files "Tape files

– Unordered files – Ordered files

"Disk files

– Unordered files – Ordered files

slide-6
SLIDE 6

rasitjutrakul

Tape Files : Unordered

Never would one use unordered sequential file if one permits InsertOne, DeleteOne, and

UpdateOne operations.

SL RetrieveAll S NBLK sba SL RetrieveOne S NBLK sba SL RetrieveOne S NBLK sba

avg

[ , ] [ , ] ( ) [ , ] ( ) = = + = 1 2 found not found

slide-7
SLIDE 7

rasitjutrakul

"Require intial sorting operation of the given file. "Batch mode update processing :

– InsertOne, DeleteOne, and UpdateOne

"Batch mode retrieve processing :

– Batch and RetrieveFew

Tape Files : Ordered

SL RetrieveAll S NBLK sba SL RetrieveOne S NBLK sba SL RetrieveOne S NBLK sba

avg

[ , ] [ , ] ( ) [ , ] ( ) = = + = 1 2 found not found

slide-8
SLIDE 8

rasitjutrakul

"A sequential file contains all logical records that are to be either updated,

deleted, and/or inserted into the master file.

– updated – deleted – inserted

Transaction Files

U Record D Record I Record

  • perational field
  • perational field
slide-9
SLIDE 9

rasitjutrakul

Batch Mode

TF

Sort Sort

NTF

Batch Update Batch Update

MF NMF

TF

: Transaction file

NTF

: New transaction file (ordered)

MF

: Master file (ordered)

NMF

: New mater file (ordered)

slide-10
SLIDE 10

rasitjutrakul

Batch Mode

D 125321Somboon I 233218Somkuan I 235089Somhatai U 255989Somsak I 817222Somwai 012834Somchai 125321Somboon 232117Somkid 255989Somsuk 592211Somsri 877652Somwang 012834Somchai 232117Somkid 233218Somkuan 235089Somhatai 255989Somsak 592211Somsri 817222Somwai 877652Somwang

Batch Update Batch Update

TF NMF MF

slide-11
SLIDE 11

rasitjutrakul

"Search length : same as the unordered tape files.

– RetrieveAll – RetrieveOne (found) – RetrieveOne (not found)

"UpdateOne can be done in place. Disk Files : Unordered

SL UpdateOne S NBLK sba

avg[

, ] = + +

L N M O Q P

1 1 2

slide-12
SLIDE 12

rasitjutrakul

Unordered Disk Files : Delete "DeleteOne : flagging the record

– same search length as UpdateOne

  • rec. # 1
  • rec. # 2
  • rec. # 3
  • rec. # n

...

SL UpdateOne S NBLK sba

avg[

, ] = + +

L N M O Q P

1 1 2

slide-13
SLIDE 13

rasitjutrakul

Unordered Disk Files : Insert "InsertOne

– append : retrieve the last block

" if there is space, rewrite the updated block

1 rba + 1 sba

" if full, get next block and rewrite the block

1 rba + 2 sba – allocate empty slot in each block

" operation cost is the same as DeleteOne

  • rec. # 5

rec.# 6

  • rec. # 7

empty slot

slide-14
SLIDE 14

rasitjutrakul

"RetrieveAll : NBLK sba "RetrieveOne :

– sequential search – binary search – step search

"UpdateOne, DeleteOne, InsertOne* :

– 1 sba + the avg SL of RetrieveOne

Disk Files : Ordered

slide-15
SLIDE 15

rasitjutrakul

Ordered Disk Files : RetrieveOne

SL UpdateOne S NBLK sba

avg

[ , ] = + +

L N M O Q P

1 1 2

SL UpdateOne S NBLK sba

avg

[ , ]= + +

L N M O Q P

1 1 2

SL UpdateOne S NBLK sba

avg [

, ] = + +

L N M O Q P

1 1 2

Sequential search Binary search Step search

slide-16
SLIDE 16

rasitjutrakul

"Deleting records by flagging

– does not physically delete the records.

"Reorganization from time to time

– Copying all unflagged records to a new file. – Purging the old file.

Reorganization

slide-17
SLIDE 17

rasitjutrakul

Physical Linked Sequential Files "Physical sequential files

– InsertOne & DeleteOne cause file to be cluttered

"Physical linked sequential files

– Block pointers preserve block adjacency. – Blocks could be dispersed on the disk. – Each block access is a random access. – Ok for highly active files.

block 1 block 1 block 2 block 2 block 3 block 3 block n block n

...

slide-18
SLIDE 18

rasitjutrakul

"Binary search can not be done. Physical Linked Sequential Files

Unordered Ordered

RetrieveAll NBLK rba NBLK rba RetrieveOne (found) (1+NBLK) / 2 rba (1+NBLK) / 2 rba RetrieveOne (not found) NBLK rba (1+NBLK) / 2 rba

block 1 block 1 block 2 block 2 block 3 block 3 block n block n

...

slide-19
SLIDE 19

rasitjutrakul

Unordered Files : InsertOne

6 6 2 4 1 6 2 4 6 2

1 rba + 1sba 1 rba + 1sba 2 rba + 1sba 1 rba + 1sba

slide-20
SLIDE 20

rasitjutrakul

Unordered Files : DeleteOne

6 2 4 1 5 8 2 4 1 5 8 2 4 1 5 2 4 1

RetrieveOne + 1 sba RetrieveOne + 1 sba RetrieveOne + 1 sba

slide-21
SLIDE 21

rasitjutrakul

Ordered Files : InsertOne

15 12 15 7 9 12 15 6 9 12 15

RetrieveOne + 1 sba

7 9 12 15 10 6 6 1 1 1 1 6 1 6

RetrieveOne + 1 rba + 1sba RetrieveOne + 1 rba + 2 sba RetrieveOne + 2 rba + 2 sba

8 9 12 15 10 1 6

RetrieveOne + 2 rba + 3 sba

7

slide-22
SLIDE 22

rasitjutrakul

Sequential Files in COBOL

FILE SECTION. FD OLD-MASTER LABEL RECORDS ARE STANDARD BLOCK CONTAINS 20 RECORDS 01 OLD-MASTER-REC. 05 M-ACCT-NO PIC X(5). 05 AMOUNT-DUE PIC 9(4)V99. 05 FILLER PIC X(89). ... OPEN INPUT OLD-MASTER TRANS-FILE OUTPUT NEW-MASTER. READ OLD-MAS-REC AT END MOVE HIGH-VALUES TO M-ACCT-NO. ... CLOSE OLD-MASTER TRANSF-FILE NEW-MASTER.