indexed files n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Indexed Files PowerPoint Presentation
Download Presentation
Indexed Files

Loading in 2 Seconds...

play fullscreen
1 / 26

Indexed Files - PowerPoint PPT Presentation


  • 130 Views
  • Uploaded on

Indexed Files. Direct Access Files. Allows records to be accessed directly Common file organizations Indexed Relative Indexed file – Two components Data - Unique key identifies each record Index - Key and disk pointer to disk interval Separate Imbedded. Indexed Files.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Indexed Files' - Patman


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
direct access files
Direct Access Files
  • Allows records to be accessed directly
  • Common file organizations
    • Indexed
    • Relative
  • Indexed file – Two components
    • Data - Unique key identifies each record
    • Index - Key and disk pointer to disk interval
      • Separate
      • Imbedded
index file select clause
Index File - SELECT CLAUSE
  • Required entries
    • ORGANIZATION IS INDEXED
    • ACCESS IS SEQUENTIALRANDOMDYNAMIC
    • RECORD KEY IS data-name identifies the primary record key within the file’s record description
index file select clause1
Index File - SELECT CLAUSE
  • Optional entries
    • [ALTERNATE RECORD KEY IS data-name-2 [WITH DUPLICATES]]
    • [FILE STATUS IS data-name-3]
      • An optional working storage item to record the status of I/O operations
creating an indexed file
Creating an Indexed File
  • Input is sorted using RECORD KEY as primary sort sequence
  • For loading purposes the indexed file is defined for SEQUENTIAL access
  • Duplicates must be removed from the Input file or trapped
    • INVALID KEY clause
    • Or FILE STATUS
creating an indexed file1
Creating an Indexed File
  • File defined as SEQUENTIAL access
  • File is OPENed for OUTPUT
  • WRITE record-name INVALID KEY- error trapping imperative statements NOT INVALID KEY imperative statementsEND-WRITE
reading an indexed file sequentially
Reading an Indexed File - Sequentially
  • ACCESS IS SEQUENTIAL – in SELECT Statement
  • File OPEN INPUT
  • READ file-name [KEY IS data-name] INVALID KEY imperative statements NOT INVALID KEY imperative statementsEND-READ
  • Alternatively you can use the READ with AT END / NOT AT END format
reading an indexed file randomly
Reading an Indexed File - Randomly
  • ACCESS IS RANDOM in SELECT statement
  • File OPEN INPUT
  • Value of RECORD KEY must be set prior to READ
  • READ file-name [KEY IS data-name] INVALID KEY imperative statements NOT INVALID KEY imperative statementsEND-READ
  • When RAMDOM ACCESS is used there is no end of file checking
updating an index file
Updating an Index File
  • Access is defined as SEQUENTIAL or RANDOM
  • File OPEN I-O
  • A Read must precede any write
  • REWRITE record-name INVALID KEY imperative statements NOT INVALID KEY imperative statementsEND-REWRITE
deleting records from an indexed file
Deleting records from an Indexed File
  • If access is SEQUENTIAL
    • READ must precede the DELETE
  • If access is RANDOM
    • the RECORD KEY must be set prior to the DELETE
  • DELETE file-name INVALID KEY imperative statements NOT INVALID KEY imperative statementsEND-DELETE
dynamic access start
DYNAMIC Access - START
  • File can be read both sequentially and randomly
  • ACCESS IS DYNAMIC in SELECT statement
  • START file-name KEY IS {=, >, >=} data-name INVALID KEY imperative statements NOT INVALID KEY imperative statementsEND-START
  • START simply positions the file’s record pointer a READ must follow
dynamic access read
DYNAMIC Access - READ
  • READ file-name NEXT RECORD AT END imperative statements NOT AT END imperative statementsEND-READ
relative files1
Relative Files
  • Data -
    • Records are accessed in a file relative to the beginning of the file
      • ACCT# 0001 will the first record in the file
      • ACCT# 0534 will be the 534th record in the file
    • Disk space must be reserved in advance
      • Every record should be primed HIGH-VALUES or LOW-VALUES
    • Some files/records the Record key readily translates into a relative file location
      • Customer records - ACCT #
      • Employee records - Employee#
relative files2
Relative Files
  • Record key may require some sort of conversion (hashing) to determine the relative position
    • SSNumber - 321301670 - 321,301,670th record ??
    • The remainder algorithm
    • Key / N ( where N is the number of expected records)
      • Take the remainder + 1 to determine relative key
      • Example if N = 5500 take 321301670 / 5500
      • Remainder = 2670 Relative key = 2671
  • Not every record location is filled with data
relative select clause
Relative - SELECT CLAUSE
  • Required entries
    • ORGANIZATION IS RELATIVE
    • ACCESS IS SEQUENTIALRANDOMDYNAMIC
    • RELATIVE KEY IS data-nameidentifies a WS item that contains the record number to be accessed
      • Unsigned Numeric
      • > 0 and <= number of records pre-allocated
      • Optional if ACCESS IS SEQUENTIAL
allocating a relative file
ALLOCATING a Relative File
  • Pre-format a file with number of records needed
  • RELATIVE file is defined for SEQUENTIAL access
  • Use a WRITE statement to add records
  • EXAMPLE –MOVE LOW-VALUES TO CUTOMER-MASTER-RECORD PERFORM 1000 TIMES WRITE CUSTOMER-MASTER-RECORD END-PERFORM
loading a relative file
LOADING A RELATIVE FILE
  • Input file not necessarily sorted
  • ACCESS IS RANDOM
  • Calculate the relative key if necessary
  • Need to READ the relative file first to be sure a record does not exist in the location
  • If the record is all LOW-VALUES okay to add at this location using a REWRITE
reading a relative file sequentially
Reading a Relative File Sequentially
  • SEQUENTIAL access
  • File OPEN INPUT
  • READ file-name AT END imperative statements NOT AT END imperative statementsEND-READ
  • Be sure to check for null records before processing
reading a relative file randomly
Reading a Relative File - Randomly
  • RANDOM access
  • File OPEN INPUT
  • RELATIVE KEY must be set prior to READ
  • READ file-name INVALID KEY imperative statements NOT INVALID KEY imperative statementsEND-READ
  • must check the record contents to verify this is the record wanted
updating a relative file
Updating a Relative File
  • Access defined as SEQUENTIAL or RANDOM
  • File OPEN I-O
  • A Read must precede any write
    • May require hashing the record key to RELATIVE KEY before accessing
  • REWRITE record-name INVALID KEY imperative statements NOT INVALID KEY imperative statementsEND-REWRITE
deleting records from a relative file
Deleting records from a RELATIVE File
  • If access is SEQUENTIAL a READ must precede the DELETE
  • If RANDOM the RELATIVE KEY must be set prior to the DELETE
  • DELETE file-name INVALID KEY imperative statements NOT INVALID KEY imperative statementsEND-DELETE
dynamic access start1
DYNAMIC Access - START
  • File can be read both sequentially and randomly
  • START file-name KEY IS {=, >, >=} data-name INVALID KEY imperative statements NOT INVALID KEY imperative statementsEND-START
  • START simply positions the file’s record pointer a READ must follow
dynamic access read1
DYNAMIC Access - READ
  • READ file-name NEXT RECORD AT END imperative statements NOT AT END imperative statementsEND-READ