Chapter 15 Indexed Sequential Files. Disk File Organization File is collection of records Three major ways records stored or organized on disk - Sequential.

Slides:



Advertisements
Similar presentations
DT266/2 Information Systems COBOL Revision. Chapters 1 & 2 Hutty & Spence Divisions of a Cobol Program Identification Division Program-ID. Environment.
Advertisements

Computer Studies Today Chapter 18 1 »Two main types of secondary storage devices: –Magnetic storage devices –Optical storage devices.
Section 6.2. Record data by magnetizing the binary code on the surface of a disk. Data area is reusable Allows for both sequential and direct access file.
2-1 Chapter 2.  Coding Requirements of IDENTIFICATION DIVISION  Sections of ENVIRONMENT DIVISION  Assigning Files to Devices in ENVIRONMENT DIVISION.
Files  File organisation and usage A record is a group of logically related fields A file is a group of logically related records Files are used to store.
Processing with VSAM Files Please use speaker notes for additional information!
What Is A Computer System?
1 Chapter 6 Storage and Multimedia: The Facts and More.
A Guide to Oracle9i1 Advanced SQL And PL/SQL Topics Chapter 9.
Chapter 8: I/O Streams and Data Files. In this chapter, you will learn about: – I/O file stream objects and functions – Reading and writing character-based.
COBOL for the 21 st Century Stern, Stern, Ley Chapter 1 INTRODUCTION TO STRUCTURED PROGRAM DESIGN IN COBOL.
Chapter 6 AN INTRODUCTION TO FILES AND FILE PROCESSING Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering.
Hard Drive / Hard Disk Functions of hard disk
VSAM KSDS and COBOL Department of Computer Science Northern Illinois University August 2005 Some of the illustrations are from VSAM: Access Method Services.
15-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
Topics Covered: Data preparation Data preparation Data capturing Data capturing Data verification and validation Data verification and validation Data.
Chapter 15 Relative Files.  File organization that converts key field to actual disk address to find location of record No need to look up disk address.
Relative Files.. Creating a Relative File $ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. CreateRelativeFromSeq. * Creates a Relative file.
Structured COBOL Programming, Stern & Stern, 9th edition
4-1 Coding Complete COBOL Programs: The PROCEDURE DIVISION Chapter 4.
4-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
12-1 Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout John.
4-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
1 Chapter 4. To familiarize you with methods used to 1. Access input and output files 2. Read data from an input file 3. Perform simple move operations.
Chapter To familiarize you with  Why COBOL is a popular business-oriented language.  Programming practices and techniques  History of COBOL.
Chapter 13 Sequential File Processing. Master Files Set of files used to store companies data in areas like payroll, inventory Usually processed by batch.
1 Week 9: Computing Components: PART II READING: Chapter 5.
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.
Programming in COBOL-85 For IBM Mainframe System 390 Jyothi Sridhar Kini E&R, Infosys Mail-id: Phone:
BIS 1753 Introduction to Computer Programming 1. Computer Program A set of instructions that enables a computer to process data Also called software Two.
Lecture 31 Numeric Edited Alphabetic (A) AlphaNumeric (X) Numeric (9, V, S) Numeric Edited (9, Z, comma, decimal point, minus sign) –Z = zero suppressed.
The DATA DIVISION Chapter 3. COBOL Data Organization Field - group of characters forming a meaningful unit or basic fact –Characters in a name or digits.
3-1 Chapter 3. To familiarize you with  Ways in which data is organized in COBOL  Rules for forming data-names  Defining input and output files in.
1 Interactive vs Batch Programs Cobol suited for developing both types of programs Interactive programs Accept input data from keyboard Input data processed.
Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File.
Chapter 7 File I/O 1. File, Record & Field 2 The file is just a chunk of disk space set aside for data and given a name. The computer has no idea what.
Indexed and Relative File Processing
1 Chapter – 12 Table Lookups Table Codes –Expanded Values –Types of Codes Numeric Alphabetic Alphanumeric.
1 Introduction to Computers By Masseta ICT Dept. Mzumbe University.
13-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
Sequential Files Chapter 13. Master Files Set of files used to store companies data in areas like payroll, inventory Set of files used to store companies.
CPSC3111/CISM3111 COBOL Structured COBOL Programming Text: murach’s structured COBOL Authors: Murach, Prince, Menendez.
© 2005 Pearson Addison-Wesley. All rights reserved Figure 2.1 This chapter focuses on key hardware layer components.
Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout.
Practical PC, 7 th Edition Chapter 4: File Basics.
Structured COBOL Programming, Stern & Stern, 9th Edition CHAPTER 2 Cobol Language Fundamentals.
1 Chapter 5 – The Procedure Division File handling statements –OPEN statement Initiates processing for a file Input Output Each file opened must have been.
13-1 Sequential File Processing Chapter Chapter Contents Overview of Sequential File Processing Sequential File Updating - Creating a New Master.
2-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.
13- 1 Chapter 13.  Overview of Sequential File Processing  Sequential File Updating - Creating a New Master File  Validity Checking in Update Procedures.
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Introduction to Files in VB Chapter 9.1, 9.3. Overview u Data Files  random access  sequential u Working with sequential files  open, read, write,
Indexed Files.. Creating an Indexed File $ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. CreateIndexedFromSeq. * Creates an indexed file.
Chapter 4 PROCEDURE DIVISION. Paragraphs PROCEDURE DIVISION divided into paragraphs Each is independent module or routine Made up of series of instructions.
VSAM ESDS and RRDS Department of Computer Science Northern Illinois University September 2005 Some of the illustrations are from VSAM: Access Method Services.
Week 2/3 - 2nd Lecture Intro to COBOL Programming Defining Files and Processing Data.
Random update Please use speaker notes for additional information!
Presentation on Database management Submitted To: Prof: Rutvi Sarang Submitted By: Dharmishtha A. Baria Roll:No:1(sem-3)
Introduction to Sequential Files. COBOL's forte  COBOL is generally used in situations where the volume of data to be processed is large.  These systems.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
I/O Resource Management: Software
Designing and Debugging Batch and Interactive COBOL Programs
Topics Introduction to File Input and Output
Chapter 3 The DATA DIVISION.
Agenda Test next Week! SI or no SI? File Update Techniques – Review.
Programming in COBOL-85 For IBM Mainframe System 390
Topics Introduction to File Input and Output
Presentation transcript:

Chapter 15 Indexed Sequential Files

Disk File Organization File is collection of records Three major ways records stored or organized on disk - Sequential File Organization - Indexed File Organization - Relative File Organization

Indexed File Organization Consists of two files  Data file - records in sequence  Index file - contains value of Each key field Disk address of record with that corresponding key field For random access, look up key field in index file to find address Then access record in data file directly

Relative File Organization When records created, key field used to compute a disk address where record is written To randomly access records  User enters key field  Disk address computed from key field  Record then accessed directly No index needed

Magnetic Disks, Disk Drives Storage media for data Can be accessed at very high speeds Have metal oxide coating that stores data as magnetized bits Disks may be floppy disk, hard disk or disk pack

Magnetic Disks, Disk Drives Data stored in concentric circles on disk called tracks Disk drives have access arm with read/write head for accessing data  Access arm can be positioned over any track on disk  Makes random access possible

Addressing Disk Records Address individual records on disks by  Surface number - top or bottom side of disk  Track number  Sector (floppy disks) or cylinder (larger units) number Sector or cylinder is wedge-shaped section of tracks

Creating an Indexed File Records written in sequence by key field as for sequential disk file Once index file created, records can be accessed randomly

ORGANIZATION: INDEXED ACCESS MODE: SEQUENTIAL ENVIRONMENT DIVISION.... INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT EXAMPLE-FILE ASSIGN TO “EXAM.DAT” ORGANIZATION IS INDEXED ACCESS MODE IS SEQUENTIAL RECORD KEY IS EXAM-KEY.... DATA DIVISION. FILE SECTION. FD EXAMPLE-FILELABEL RECORDS ARE STANDARD RECORD CONTAINS 100 CHARACTERS. * 01 EXAMPLE-REC. 05 EXAM-KEYPIC X(5).... I/O STATEMENTS BY OPEN MODE OPEN MODE: INPUT OPEN INPUT EXAMPLE-FILE. READ EXAMPLE-FILE AT END MOVE “Y” TO WS-EOF-FLAG. CLOSE EXAMPLE-FILE.

ORGANIZATION: INDEXED ACCESS MODE: SEQUENTIAL OPEN MODE: OUTPUT OPEN OUTPUT EXAMPLE-FILE. MOVE value TO EXAM-KEY. WRITE EXAMPLE-REC INVALID KEY MOVE “Y” TO WS-WRITE-ERR-FLAG NOT INVALID KEY ADD 1 TO WS-WRITE-CTR. CLOSE EXAMPLE-FILE. OPEN MODE: INPUT-OUTPUT OPEN I-O EXAMPLE-FILE. DELETE EXAMPLE-FILE RECORD. READ EXAMPLE-FILE AT END MOVE “Y” TO WS-EOF-FLAG. REWRITE EXAMPLE-REC INVALID KEY MOVE “Y” TO WS-REWRITE-ERR-FLAG. CLOSE EXAMPLE-FILE.

FILE STATUS Clause To determine exact type of input or output error that occurred when accessing a file Included in SELECT statement for a file as last clause SELECT … [FILE STATUS IS data-name] Format

FILE STATUS Clause Data-name must appear in WORKING- STORAGE as two-position alphanumeric field Select Indexed-Pay-File … File Status Is WS-Status. … Working-Storage Section. 01WS-Status Pic X(2). Example

FILE STATUS Clause When input or output operation performed on Indexed-Pay-File  Value placed in WS-Status  Can be tested by programmer in PROCEDURE DIVISION Several FILE STATUS field values and their meaning follow

FILE STATUS Values File Status Field ValueMeaning 00 No error occurred 21Sequence error - keys not in correct order 22Attempt to write record creating duplicate primary record key

Checking FILE STATUS Write Indexed-Pay-Rec Invalid Key If WS-Status = '21' Display 'Key not in sequence' End-If … Not Invalid Key Perform 600-OK-Rtn End-Write

ORGANIZATION: INDEXED ACCESS MODE: RANDOM ENVIRONMENT DIVISION.... INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT EXAMPLE-FILE ASSIGN TO “EXAM.DAT” ORGANIZATION IS INDEXED ACCESS MODE IS RANDOM RECORD KEY IS EXAM-KEY.... DATA DIVISION. FILE SECTION. FD EXAMPLE-FILELABEL RECORDS ARE STANDARD RECORD CONTAINS 100 CHARACTERS. * 01 EXAMPLE-REC. 05 EXAM-KEYPIC X(5).... I/O STATEMENTS BY OPEN MODE OPEN MODE: INPUT OPEN INPUT EXAMPLE-FILE. MOVE value TO EXAM-KEY. READ EXAMPLE-FILE INVALID KEY MOVE “Y” TO WS-EOF-FLAG. CLOSE EXAMPLE-FILE.

ORGANIZATION: INDEXED ACCESS MODE: RANDOM OPEN MODE: OUTPUT OPEN OUTPUT EXAMPLE-FILE. MOVE value TO EXAM-KEY. WRITE EXAMPLE-REC INVALID KEY MOVE “Y” TO WS-WRITE-ERR-FLAG NOT INVALID KEY ADD 1 TO WS-WRITE-CTR. CLOSE EXAMPLE-FILE. OPEN MODE: INPUT-OUTPUT OPEN I-O EXAMPLE-FILE. MOVE value TO EXAM-KEY. DELETE EXAMPLE-FILE RECORD INVALID KEY MOVE “Y” TO WS-DELETE-ERR-FLAG. MOVE value TO EXAM-KEY. READ EXAMPLE-FILE AT INVALID KEY MOVE “Y” TO WS-READ-ERR-FLAG. REWRITE EXAMPLE-REC INVALID KEY MOVE “Y” TO WS-REWRITE-ERR-FLAG. MOVE value TO EXAM-KEY. WRITE EXAMPLE-REC INVALID KEY MOVE “Y” TO WS-WRITE-ERR-FLAG. CLOSE EXAMPLE-FILE.

Debugging Tips Must run program to create indexed file  Cannot be created using text editor To test an update program, always run index file creation program first May not be able to DISPLAY or print indexed records on your system directly  Move data to standard sequential record first

Random Interactive Inquiries Inquiries often made interactively with output displayed on screen Assume indexed accounts receivable file with customer's Acct-No as key field Interactive inquiries made about balance due for a customer Code using random access for one inquiry follows

Random Interactive Inquiries Display 'Enter account number' Accept Acct-No Read Accts-Receivable Invalid Key Display 'Account not on file' Not Invalid Key Display 'Balance due = ', Bal-Due End-Read

ALTERNATE RECORD KEY Clause to enable file to be accessed randomly using more than one key field - May want to access accounts receivable records by account number or name Add to SELECT statement after RECORD KEY clause to establish multiple key fields for indexing

ALTERNATE RECORD KEY [ALTERNATE RECORD KEY IS data-name-2 [WITH DUPLICATES] ] … Multiple ALTERNATE keys allowed Need not be unique Access records by RECORD KEY or any ALTERNATE RECORD KEYs Format

Random Access by ALTERNATE To access file by Cst-Last-Name Display 'Enter last name' Accept Cst-Last-Name Read Accts-Receivable Key is Cst-Last-Name Invalid Key Display 'No record found' Not Invalid Key Display 'Balance due = ', Bal-Due End-Read

Random Access by ALTERNATE KEY clause used with READ to specify access by ALTERNATE RECORD KEY Since WITH DUPLICATES specified  May be more than one record with same last name  Record retrieved is first one placed on disk If KEY clause omitted, uses RECORD KEY field (Acct-No) to find record

START Statement To begin processing indexed file sequentially starting from any record location  Print file beginning with customer record with Acct-No = 025  Print all customers with Cst-Last-Name beginning with letter 'S'

START Statement To begin processing with record whose account number equals 025 Move 025 To Acct-No Start Accts-Receivable Invalid Key Display 'Acct-No 025 not found' Not Invalid Key Perform 300-Proc-Rec End-Start

START Statement START locates record with Acct-No = 025 INVALID KEY clause executed only if no such record found START locates record but does not READ it 300-Proc-Rec must include READ … AT END to bring record into storage for processing

START Statement KEY clause can be omitted only if checking for value equal to RECORD KEY value To locate record with Acct-No > 100: Move 100 To Acct-No Start Accts-Receivable Key > Acct-No Invalid Key …...

ACCESS IS DYNAMIC Mode used to access indexed file both randomly and sequentially in single program For example, update selected records, then print control listing of entire indexed file  Random access used for updating  Sequential access used for printing report

ACCESS IS DYNAMIC Mode required for reading records in sequence by ALTERNATE RECORD KEY Also required when records accessed by both RECORD KEY and ALTERNATE RECORD KEY

READ … NEXT RECORD To perform sequential read of indexed file when ACCESS MODE IS DYNAMIC To sequentially read from file by its ALTERNATE RECORD KEY To begin reading sequentially from some point other than beginning of file

READ … NEXT RECORD Assume first record with Acct-No > 100 has been located using START Use READ … NEXT RECORD to read in records sequentially from this position Only word NEXT required

READ … NEXT RECORD Perform Until No-More-Records Read Accts-Receivable Next Record At End Move 'NO' To WS-EOF-FLAG Not At End Perform 300-Proc-Rec End-Read End-Perform