Presentation is loading. Please wait.

Presentation is loading. Please wait.

Indexed File Processing

Similar presentations


Presentation on theme: "Indexed File Processing"— Presentation transcript:

1 Indexed File Processing
Chapter 15 Indexed File Processing

2 EMPLOYEE.DATA file 000001SAKAGUCHI TORU SA2500001000000
000002KOWOLONEK RANDY SA 000003KIM JIN HR 000004IQBAL JAVID HR 000005CETRULO AMY 000006PEACE JENNIFER SA 000007DAVIS SCOTT HR 000008EDMISTEN JESSIE SA 000009ROBINSONELSENERAPRIL HR 000010BATTLES JOHN HR 000011REED MARY HR 000012EATON NICK SA

3 Creating an Indexed File
When the file is created, special information about the file is stored that allows direct record access based on the key

4 Creating an Indexed File
SELECT EMPLOYEE-FILE ASSIGN TO “EMPLOYEE.DATA” ACCESS IS SEQUENTIAL ORGANIZATION IS SEQUENTIAL. SELECT EMPLOYEE-FILE ASSIGN TO “EMPLOYEE.DATA” ACCESS IS RANDOM ORGANIZATION IS INDEXED RECORD KEY IS EMPLOYEE-NUMBER.

5 Sample 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). PIC X(45). PROCEDURE DIVISION. 000-CREATE-EMPLOYEE-FILE. OPEN OUTPUT EMPLOYEE-FILE CLOSE EMPLOYEE-FILE STOP RUN .

6 Indexed 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.

7 Adding records to an indexed file
See BUILD program

8

9 Processing an Indexed File
Your program can: Add records WRITE record-name Modify records REWRITE record-name Delete records DELETE record-name

10

11

12 Dynamic File Processing
Your program can “jump” to a position somewhere in the file and then begin processing sequentially.


Download ppt "Indexed File Processing"

Similar presentations


Ads by Google