Agenda Test next Week! SI or no SI? File Update Techniques – Review
File Access Techniques
Sequential Access Reads one record at a time Reads records in keyed sequence or arrival sequence
Random Access Records are processed in some other order than the one in which they were physically written to the disk or indexed. A key field is looked up in an index, the address is retrieved and the record is accessed from the physical file using the address.
Dynamic Access Defined when a file will be used both randomly and sequentially
Due to Normalization Practices, we usually have more than one file in our databases.
Employee Database Employeepf Provinces K Emp No K Prov Cde Prov Cde Foreign Key Empnotpf K Emp No K Note No
Defining a Sequential Access File SELECT Employee-File ASSIGN to DATABASE-EMPPF ORGANIZATION is INDEXED ACCESS MODE is SEQUENTIAL RECORD KEY is EXTERNALLY-DESCRIBED-KEY.
Defining a Random Access File SELECT Employee-File ASSIGN to DATABASE-EMPPF ORGANIZATION is INDEXED ACCESS MODE is RANDOM RECORD KEY is EXTERNALLY-DESCRIBED-KEY (with duplicates).
Defining a Dynamic Access File SELECT Employee-File ASSIGN to DATABASE-EMPPF ORGANIZATION is INDEXED ACCESS MODE is DYNAMIC RECORD KEY is EXTERNALLY-DESCRIBED-KEY (with duplicates).
Beware of File Status Code 95! Need to add ‘WITH DUPLICATES’ to your select statement or your need to take it out!
Randomly Retrieve a Record using a Random Defined File Update the Key Fields in the File. READ file-name INVALID KEY Perform invalid-logic NOT INVALID KEY Perform valid-logic END-READ.
Sequential Read using a Random Defined File?
Sequentially Read using a Random Defined Record Make sure that ACCESS is DYNAMIC!! READ file-name NEXT RECORD AT END Perform perform end-of-file-logic END-READ.
Positioning the File Pointer Used only with Sequentially defined files. Initialize the record key START file-name Key Condition INVALID KEY Perform Invalid-Logic NOT INVALID KEY Perform valid-logic END-START.
Other Random Access Verbs
REWRITE Updates a record in a file File must be opened as I-O instead of input Record must be read first before rewrite REWRITE record-name (FROM variable-name) INVALID KEY perform error-rtn NOT INVALID KEY perform continue-rtn END-REWRITE.
DELETE Deletes a record from a file File must be opened as I-O The record must be read first DELETE file-name RECORD INVALID KEY perform error-rtn NOT INVALID KEY perform continue-rtn END-DELETE.
WRITE Writes records to a file File must be opened as I-O or OUTPUT WRITE record-name (FROM variable) INVALID KEY perform error-rtn NOT INVALID KEY perform continue-rtn END-WRITE.
CPCH13B