Chapter 15 Indexed File Processing EMPLOYEE DATA file

  • Slides: 12
Download presentation
Chapter 15 Indexed File Processing

Chapter 15 Indexed File Processing

EMPLOYEE. DATA file 000001 SAKAGUCHI TORU 000002 KOWOLONEK RANDY 000003 KIM JIN 000004 IQBAL

EMPLOYEE. DATA file 000001 SAKAGUCHI TORU 000002 KOWOLONEK RANDY 000003 KIM JIN 000004 IQBAL JAVID 000005 CETRULO AMY 000006 PEACE JENNIFER 000007 DAVIS SCOTT 000008 EDMISTEN JESSIE 000009 ROBINSONELSENERAPRIL 000010 BATTLES JOHN 000011 REED MARY 000012 EATON NICK SA 2500001000000 SA 1825001110050 HR 0715000120900 HR 0455000090000 9999999 SA 3000001100000 HR 0800000094500 SA 2000003400500 HR 0750002045600 HR 0630000876250 HR 0900002340200 SA 3325011011100

Creating an Indexed File • When the file is created, special information about the

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

Creating an Indexed File • SELECT EMPLOYEE-FILE ASSIGN TO “EMPLOYEE. DATA” ACCESS IS SEQUENTIAL

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 EMPLOYEENUMBER.

Sample Code IDENTIFICATION DIVISION. PROGRAM-ID. CREATEIND. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT EMPLOYEE-FILE ASSIGN

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

Indexed Files • The only way that you can identify the type of file

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.

Adding records to an indexed file • See BUILD program

Adding records to an indexed file • See BUILD program

Processing an Indexed File • Your program can: – Add records • WRITE record-name

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

Dynamic File Processing • Your program can “jump” to a position somewhere in the

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