250 likes | 431 Views
Indexed Files. Direct Access Files. Allows records to be accessed directly Common file organizations Indexed Relative Indexed file Data - Unique key identifies each record Index - Key and disk pointer to disk interval Separate Imbedded. Indexed Files. Indexed Files - Blocked Records.
E N D
Direct Access Files • Allows records to be accessed directly • Common file organizations • Indexed • Relative • Indexed file • Data - Unique key identifies each record • Index - Key and disk pointer to disk interval • Separate • Imbedded
Indexed Files - Blocked Records Find B10 A15 B30 E18 A01 A05 A15 B04 B10 B30 E01 E07 E18
377 Vert.Pntr 619 Vert.Pntr 800 Vert.Pntr Horiz.Pntr. Sequence Set Sequence Set Sequence Set Horiz.Pntr. 280 Vert.Pntr 327 Vert.Pntr 377 Vert.Pntr 469 Vert.Pntr 619 Vert.Pntr 700 Vert.Pntr 800 Vert.Pntr 251 312 345 394 500 FREE 627 717 FREE 269 318 346 400 502 642 722 280 327 377 449 598 658 746 FREE FREE FREE 469 617 675 748 FREE 619 700 800 Figure 18.1 Initial VSAM Data Set Index Set ControlInterval ControlInterval ControlInterval Control Area Control Area Control Area
377 Vert.Pntr 619 Vert.Pntr 800 Vert.Pntr 280 Vert.Pntr 327 Vert.Pntr 377 Vert.Pntr Figure 18.2 Control Interval Split Index Set Horiz.Pntr. Sequence Set Sequence Set Sequence Set Horiz.Pntr. 469 Vert.Pntr 619 Vert.Pntr 700 Vert.Pntr 730 Vert.Pntr 251 312 345 394 500 FREE 627 717 746 269 318 346 400 502 642 722 748 280 327 377 449 598 658 730 800 FREE FREE FREE 469 617 675 FREE FREE FREE 619 700 Control IntervalSplit Control Area Control Area Control Area
658 730 469 Vert.Pntr Vert.Pntr Vert.Pntr 700 598 800 Vert.Pntr Vert.Pntr Vert.Pntr Vert.Pntr Vert.Pntr 619 Vert.Pntr 280 Vert.Pntr 327 Vert.Pntr 377 Vert.Pntr 251 312 617 500 345 627 746 675 717 FREE FREE 316 269 346 748 722 618 502 642 680 318 280 377 730 598 619 658 800 700 327 FREE FREE FREE FREE FREE FREE FREE FREE FREE Figure 18.3 Control Area Split 377 Vert.Pntr 619 Vert.Pntr 700 Vert.Pntr 800 Vert.Pntr Index Set Horiz.Pntr. Horiz.Pntr. Horiz.Pntr. Sequence Set Sequence Set Sequence Set Sequence Set 394 400 410 449 469 Control IntervalSplit Control IntervalSplit Control Area Control Area Control Area Control Area Control Area Split
Index File - SELECT CLAUSE • 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 CLAUSE • [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
Table 18.1 File Status Codes 00 A successful input/output operation is performed with no further information available/02 A successful creation of a record with duplicate alternate key value.04 A READ is successful, but the length of the record being processed does not conform to the fixed file attributes for that file . 05 An OPEN is successful, but the referenced optional file is not present at open time.07 An input/output statement is successful; however, for a CLOSE with NO REWIND, REEL/UNIT, or FOR REMOVAL or for an OPEN with NO REWIND the reverenced file is on a nonreel/unit medium.10 A sequential READ is attempted and no next logical record exists because (1) the end of file has been reached; or (2) an optional input file is not present.14 A sequential READ is attempted and the number of significant digits in the record number is larger than the size of the key data item described for the file.15 A sequential READ statement is attempted for the first time on an optional file that is not present.21 A sequence error exists for a sequentially accessed indexed file.22 An attempt is made to write or rewrite a record that would create a duplicate prime record key or duplicate alternate record key without the DUPLICATES phrase.23 An attempt is made to randomly access a record that does not exist in the file, or a START or random READ is attempted on an optional input file that is not present.24 An attempt is made to write beyond the externally defined boundaries.25 A START statement or a random READ statement has been attempted on an optional file that is not present.30 A permanent error exists and not further information is available concerning the input/output operation.
File Status Codes 34 A permanent error exists because of a boundary violation; an attempt is made to write beyond the externally defined boundaries.35 A permanent error exists because an OPEN with the INPUT, I/O, or EXTEND phrase is attempted on a nonoptional file that is not present.37 A permanent error exists because an OPEN is attempted on a file and that file will not support the open mode specified: (1) EXTEND or OUTPUT phrase specified but not supported by the file; (2) I/O phrase is specified, but input and output operations are not supported by the file; or (3) INPUT phrase is specified, but the file will not support READ operations.38 A permanent error exists because an OPEN is attempted on a file previously closed with a lock.39 The OPEN is unsuccessful because a conflict has been detected between the fixed file attributes and the ones specified for that file in the program.41 An OPEN statement is attempted for a file in the open mode.42 A CLOSE statement is attempted for a file not in the open mode.43 In the sequential access mode, the last input/output statement executed for the file prior to the execution of a DELETE or REWRITE statement was not a successfully executed READ statement.44 A boundary violation exists because of an attempt to : (1) write or rewrite a record that is larger than the largest or smaller than the smallest record allowed by the RECORD IS VARYING clause of the associated file-name, or (2) rewrite a record and the record is not the same size as the record being replaced.
File Status Codes 46 A sequential READ is attempted on a file open in the input or I/O mode and no valid next record has been established because the preceding: (1) START was unsuccessful, (2) READ was unsuccessful but did not cause an at-end condition or (3) READ caused an at-end condition.47 The execution of a READ or START is attempted on a file not open in the input or I/O mode.48 The execution of a WRITE is attempted on a file not open in the I/O, output, or extend mode.49 The execution of a DELETE or REWRITE statement is attempted on a file not open in the input or I/O mode.
Creating an Indexed File • Input is a sorted sequential file • Index file is defined for SEQUENTIAL access • Duplicates must be removed from the Input file or trapped using the FILE STATUS
Figure 18.4 Pseudocode for Creating Indexed File Open filesDO WHILE data remains READ record from sequential file AT END Indicate no more data NOT AT END Move sequential record to indexed record Write indexed record IF sequence error Display error - record out of sequence ENDIF IF duplicate record Display error - record already exists ENDIF ENDREADENDDOClose filesStop run
Figure 18.6 Display Output of Create Program OPEN statement executed without error OPEN STATEMENT EXECUTED FILE STATUS BYTES = 00 WRITE STATEMENT EXECUTED FOR 100000000GRABER P ATL1500000000 FILE STATUS BYTES = 00 WRITE STATEMENT EXECUTED FOR 200000000RUBIN MABOS0800020000 FILE STATUS BYTES = 00 WRITE STATEMENT EXECUTED FOR 300000000ANDERSON IRGOS1000113000 FILE STATUS BYTES = 00 ERROR (SEQUENCE) FOR 222222222PANZER S NYC0600000000WRITE STATEMENT EXECUTED FOR 222222222PANZER S NYC0600000000 FILE STATUS BYTES = 21 WRITE STATEMENT EXECUTED FOR 400000000MOLDOF BLATL1500000000 FILE STATUS BYTES = 00 WRITE STATEMENT EXECUTED FOR 500000000GLASSMAN JSNYC1000045000 FILE STATUS BYTES = 00 WRITE STATEMENT EXECUTED FOR 600000000GRAUER RTNYC0800087500 FILE STATUS BYTES = 00 WRITE STATEMENT EXECUTED FOR 700000000MILGROM A SF 0900120000 FILE STATUS BYTES = 00 WRITE STATEMENT EXECUTED FOR 800000000VASQUEZ C ATL1200060000 FILE STATUS BYTES = 00 WRITE STATEMENT EXECUTED FOR 900000000CLARK E NYC0700002500 FILE STATUS BYTES = 00 CLOSE STATEMENT EXECUTED FILE STATUS BYTES = 00 Sequence error for Panzer CLOSE statement executed without error
Writing an Indexed File • File defined as SEQUENTIAL access • File OPEN OUTPUT • WRITE record-name INVALID KEY imperative statements NOT INVALID KEY imperative statementsEND-WRITE
Reading an Indexed File • SEQUENTIAL access • File OPEN INPUT • READ file-name [KEY IS data-name] INVALID KEY imperative statements NOT INVALID KEY imperative statementsEND-READ
Reading an Indexed File • RANDOM access • File OPEN INPUT • 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
Updating an Index File • Access 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 • If access is SEQUENTIAL a READ must precede the DELETE • If RANDOM the RECORD KEY must be set prior to the DELETE • DELETE file-name INVALID KEY imperative statements NOT INVALID KEY imperative statementsEND-DELETE
Figure 18.8 Hierarchy Chart for Nonsequential Update Program
Figure 18.9 Pseudocode for Nonsequential Update Program Open filesDO WHILE data remains READ transaction file AT END Indicate no more data NOT AT END Move transaction social security number to record key READ INDEXEC-FILE INVALID KEY Move ‘NO’ TO record-key-allocated-switch NOT INVALID KEY Move ‘YES’ TO record-key-allocated-switch END-READ EVALUATE WHEN addition IF record-key-allocated-switch = ‘YES’ Write ‘error - duplicate addition’ ELSE (transaction is not in indexed file) Move transaction-record to new-master-record Write indexed-record ENDIF WHEN correction IF record-key-allocated-switch = ‘YES’ Process correction Rewrite indexed record ELSE (transaction is not in indexed file) Write ‘error - no matching record’ ENDIF WHEN deletion IF record-key-allocated-switch = ‘YES’ Delete indexed record ELSE (transaction is not in indexed file) Write ‘error - no matching record’ ENDIF WHEN other Write ‘error - invalid transaction’ END EVALUATE END READEND DOClose FilesStop Run
Figure 18.7 Test Data for Nonsequential Update 100000000GRABER P ATL1500000000 200000000RUBIN MABOS0800020000 300000000ANDERSON IRGOS1000113000400000000MOLDOF BLATL1500000000 500000000GLASSMAN JSNYC1000045000 600000000GRAUER RTNYC0800087500700000000MILGROM A SF 0900120000800000000VASQUEZ C ATL1200060000900000000CLARK E NYC0700002500 (a) Indexed File (before Update) 4444444444RICHARDS IM 05000C 7000000000MILGROM A D 000000000BOROW JSATL07 A 000000000BOROW JS 10000C 000000000BOROW JQ 20000C 400000000MOLDOF BLATL15 A 800000000VASQUEZ C 55000C 999999999GILLENSON MANYC10 A Transactions are not in sequential order (b) Transaction File 000000000BOROW JSATL0700030000 100000000GRABER P ATL1500000000 200000000RUBIN MABOS0800020000 300000000ANDERSON IRGOS1000113000222222222PANZER S NYC0600000000 400000000MOLDOF BLATL1500000000 500000000GLASSMAN JSNYC1000045000 600000000GRAUER RTNYC0800087500700000000MILGROM A SF 0900120000800000000VASQUEZ C ATL1200115000900000000CLARK E NYC0700002500 999999999GILLENSON MANYC1000000000 (c) Indexed File (after Update) ERROR-NO MATCHING RECORD: 444444444 ERROR-DUPLICATE ADDITION: 400000000 (d) Error Messages
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 - READ • READ file-name NEXT RECORD AT END imperative statements NOT AT END imperative statementsEND-READ