Title: Indexed File Processing
1Chapter 15
2EMPLOYEE.DATA file
000001SAKAGUCHI TORU
SA2500001000000 000002KOWOLONEK RANDY
SA1825001110050 000003KIM JIN
HR0715000120900 000004IQBAL JAVID
HR0455000090000 000005CETRULO AMY
9999999999999 000006PEACE
JENNIFER SA3000001100000 000007DAVIS
SCOTT HR0800000094500 000008EDMISTEN
JESSIE SA2000003400500 000009ROBINSONE
LSENERAPRIL HR0750002045600 000010BATTLES
JOHN HR0630000876250 000011REED
MARY HR0900002340200 000012EAT
ON NICK SA3325011011100
3Creating an Indexed File
- When the file is created, special information
about the file is stored that allows direct
record access based on the key
4Creating an Indexed File
- SELECT EMPLOYEE-FILE ASSIGN TO
EMPLOYEE.DATA ACCESS IS SEQUENTIAL ORGANIZATIO
N IS SEQUENTIAL. - SELECT EMPLOYEE-FILE ASSIGN TO
EMPLOYEE.DATA ACCESS IS RANDOM ORGANIZATION
IS INDEXED RECORD KEY IS EMPLOYEE-NUMBER.
5Sample Code
IDENTIFICATION DIVISION. PROGRAM-ID.
CREATEIND. ENVIRONMENT DIVISION. INPUT-OUTPUT
SECTION. FILE-CONTROL. SELECT EMPLOYEE-FILE
ASSIGN TO EMPLOYEE.DATA
ORGANIZATION IS INDEXED RECORD KEY IS
EMPLOYEE-NUMBER. DATA DIVISION. FILE SECTION. FD
EMPLOYEE-FILE 01 EMPLOYEE-RECORD. 05
EMPLOYEE-NUMBER PIC X(6). 05
PIC X(45). PROCEDURE DIVISION. 000-CREATE-EMPLOYE
E-FILE. OPEN OUTPUT EMPLOYEE-FILE CLOSE
EMPLOYEE-FILE STOP RUN .
6Indexed Files
- The only way that you can identify the type of
file being created is by inspecting the SELECT
clause. - Your program cannot add two records with the same
key value. The key field must be unique in the
file. - The records must be in ascending order on the key
field. - One of the advantages of indexed files is that
you can process them either randomly or
sequentially.
7Adding records to an indexed file
8(No Transcript)
9Processing an Indexed File
- Your program can
- Add records
- WRITE record-name
- Modify records
- REWRITE record-name
- Delete records
- DELETE record-name
10(No Transcript)
11(No Transcript)
12Dynamic File Processing
- Your program can jump to a position somewhere
in the file and then begin processing
sequentially.