Advanced Sequential Files 1.. Single Record Type Files  In a file which contains only one record type (the kind we have examined so far) the record structure.

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

Database Basics. What is Access? Database management system Computer-based equivalent of a manual database Makes it easy to organize and update information.
2-1 Chapter 2.  Coding Requirements of IDENTIFICATION DIVISION  Sections of ENVIRONMENT DIVISION  Assigning Files to Devices in ENVIRONMENT DIVISION.
Cobol application using ODBC or File processing Vandana Janeja CIS 365 With COBOL OR PowerCobol.
Module 7 Sorting.  The StudentFile is a sequential file sequenced upon ascending StudentId.  How to sort the file by StudentId? DATA DIVISION. FILE.
Chapter 6 Structured Data 1. A data structure, or record, in COBOL is a method of combining several variables into one larger variable. – Example: 2.
3-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emertius)
Introduction to C Programming
- Kav Shrestha.  Introduction  History  Features  COBOL Usage  Characteristics  Structure of COBOL Programs  COBOL Divisions  Data Items  Variable.
Conditions.. IF Syntax.   Simple Conditions l Relation Conditions l Class Conditions l Sign Conditions   Complex Conditions   Condition Names 
Chapter 15 Indexed Sequential Files. Disk File Organization File is collection of records Three major ways records stored or organized on disk - Sequential.
The IDENTIFICATION and ENVIRONMENT DIVISIONS Chapter 2.
CHAPTER 6 FILE PROCESSING. 2 Introduction  The most convenient way to process involving large data sets is to store them into a file for later processing.
DISK STORAGE INDEX STRUCTURES FOR FILES Lecture 12.
1.A file is organized logically as a sequence of records. 2. These records are mapped onto disk blocks. 3. Files are provided as a basic construct in operating.
Chapter 8 Printing 1. In COBOL you send data to the printer by writing data to a file. In COBOL, the printer is defined as a file, and it is opened, closed,
4-1 Coding Complete COBOL Programs: The PROCEDURE DIVISION Chapter 4.
COBOL Basics 1. COBOL coding rules  Almost all COBOL compilers treat a line of COBOL code as if it contained two distinct areas. These are known as;
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.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 17 Disk Storage, Basic File Structures, and Hashing.
Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout.
3-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emertius)
History COBOL (Common Business Oriented Language) was one of the earliest high-level programming languages. COBOL was first proposed in 1959 by the Conference.
Programming in COBOL-85 For IBM Mainframe System 390 Jyothi Sridhar Kini E&R, Infosys Mail-id: Phone:
March 16 & 21, Csci 2111: Data and File Structures Week 9, Lectures 1 & 2 Indexed Sequential File Access and Prefix B+ Trees.
Agenda Reporting Work on Assignment 4! Printing on power systems.
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.
3-1 The DATA DIVISION Chapter Chapter Objectives To familiarize you with Systems design considerations Ways in which data is organized Rules for.
Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File.
COBOL Basics 2. H E N N E S S Y R M L M F Group Items/Records StudentDetails WORKING-STORAGE SECTION. 01StudentDetailsPIC X(26).
Module 2 Defining Data Revised Defining Data All definitions of data for COBOL takes place in the DATA DIVISION. All data defined are visible to.
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
Edit Programs Please use speaker notes for additional information. Example: payedit.cbl payedit.cbl.
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.
Statement Syntax1 THE SELECT STATEMENT Purpose: designates a file and points to its physical location Syntax Definition : SELECT file-name-1 ASSIGN TO.
1 IDENTIFICATION and ENVIRONMENT DIVISIONS. 2 Objectives Basic Structure of COBOL Programs General Coding and Formatting Rules Identification and the.
INPUT / OUTPUT STATEMENTS
File Structures. 2 Chapter - Objectives Disk Storage Devices Files of Records Operations on Files Unordered Files Ordered Files Hashed Files Dynamic and.
Any Questions!. Test Coming Up! Agenda Printing with Externally Described Printer Files Arrays.
1 Chapter 5 – The Procedure Division File handling statements –OPEN statement Initiates processing for a file Input Output Each file opened must have been.
Sort and Merge.  The StudentFile is a sequential file sequenced upon ascending StudentId.  Write a program to display the number of students taking.
Chapter 9: Advanced SQL and PL/SQL Guide to Oracle 10g.
13-1 Sequential File Processing Chapter Chapter Contents Overview of Sequential File Processing Sequential File Updating - Creating a New Master.
Machine Independent Assembler Features
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.
1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.
Lecture 21 ENVIRONMENT DIVISION  defines files external to the program and devices.  contains two sections: 1.CONFIGURATION SECTION.  identifies computers.
13- 1 Chapter 13.  Overview of Sequential File Processing  Sequential File Updating - Creating a New Master File  Validity Checking in Update Procedures.
Any Questions? Week 1 - 2nd Lecture Intro to COBOL Programming Defining Files and Processing Data.
COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
Analysis of SAMPLE1.CBL Please check speaker notes for additional information!
The PERFORM. The PERFORM Verb  Iteration is an important programming construct. We use iteration when we need to repeat the same instructions over and.
Week 2/3 - 2nd Lecture Intro to COBOL Programming Defining Files and Processing Data.
Random update Please use speaker notes for additional information!
Chapter 5 Record Storage and Primary File Organizations
Sequential Processing to Update a File Please use speaker notes for additional information!
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 Streams. Objectives Learn about the classes that support file input/output Understand the concept of abstraction and how it related to the file.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Submitting Instructions on web site CS 1024 students Read guide
Week 12 Option 3: Database Design
Disk storage Index structures for files
Any Questions?.
Chapter 3 The DATA DIVISION.
Please use speaker notes for additional information!
Structured COBOL Programming
Programming in COBOL-85 For IBM Mainframe System 390
CHAPTER 17 The Report Writer Module
Presentation transcript:

Advanced Sequential Files 1.

Single Record Type Files  In a file which contains only one record type (the kind we have examined so far) the record structure is described as part of the file FD using an 01 level number.  The record description creates a ‘buffer’ capable of storing one record instance at a time.  Each time a record is read from the file it overwrites the previous contents of the buffer.  The record buffer is the only connection between the file and the program.

Multiple Record Type Files  Quite often a single file will contain more than one type of record.  For instance, some of the terminal exercises required that your program apply a file of transaction records to the StudentsFile.  For simplicity, the Transaction file in these exercises contained one record type only; either Insertion or Update or Deletion.  In a real environment, transactions of this sort would normally be collected together into one single transaction file.

Implications of a multiple record transaction file.  Gathering all the transactions into a single file implies that the file will contain different record types (i.e. records with different structures).  The different record structures may give rise to records which are also of different lengths.  For example l an insertion transaction will contain all the fields that appear in the StudentFile record (). l an insertion transaction will contain all the fields that appear in the StudentFile record (32 characters). l a deletion transaction will contain only the StudentId (). l a deletion transaction will contain only the StudentId (7 characters). l an update transaction used to record course changes might contain the StudentId, the OldCourseCode and the NewCourseCode (). l an update transaction used to record course changes might contain the StudentId, the OldCourseCode and the NewCourseCode (15 characters).

Describing multiple record files  To describe these different record types we have to use more than one record description in the file's FD.  Because record descriptions always begin with level 01 we provide a 01 level for each record type in the file.

 What is not obvious from this description is that COBOL continues to create just a single ‘record buffer’ for the file!  And this ‘record buffer’ is only able to store a single record at a time! DATA DIVISION. FILE SECTION. FD TransactionFile. 01 InsertionRec. 02 StudentId PIC 9(7). 02 StudentName. 03 Surname PIC X(8). 03 Initials PIC XX. 02 DateOfBirth. 03 YOBirth PIC 9(2). 03 MOBirth PIC 9(2). 03 DOBirth PIC 9(2). 02 CourseCode PIC X(4). 02 Grant PIC 9(4). 02 Gender PIC X. 01 DeleteRec. 02 StudentId PIC 9(7). 01 UpdateRec. 02 StudentId PIC 9(7). 02 OldCourseCode PIC X(4). 02 NewCourseCode PIC X(4). Multiple record descriptions - One record buffer

 Multiple record descriptions in a file are IMPLICITLY redefinitions of the single record buffer H E N N E S S Y R M L M F TransactionFile Buffer

 Multiple record descriptions in a file are IMPLICITLY redefinitions of the single record buffer. InsertionRec InsertionRec StudentId StudentName DateOfBirth CourseCode Grant Gender InsertionRec InsertionRec StudentId StudentName DateOfBirth CourseCode Grant Gender H E N N E S S Y R M L M F TransactionFile Buffer

 Multiple record descriptions in a file are IMPLICITLY redefinitions of the single record buffer. InsertionRec InsertionRec StudentId StudentName DateOfBirth CourseCode Grant Gender InsertionRec InsertionRec StudentId StudentName DateOfBirth CourseCode Grant Gender StudentIdDeletionRec DeletionRec H E N N E S S Y R M L M F TransactionFile Buffer

 Multiple record descriptions in a file are IMPLICITLY redefinitions of the single record buffer. InsertionRec InsertionRec StudentId StudentName DateOfBirth CourseCode Grant Gender InsertionRec InsertionRec StudentId StudentName DateOfBirth CourseCode Grant Gender StudentIdDeletionRec DeletionRec StudentId OldCourseCode NewCourseCode UpdateRec UpdateRec StudentId OldCourseCode NewCourseCode UpdateRec UpdateRec H E N N E S S Y R M L M F TransactionFile Buffer

 All these record descriptions are valid at the same time.  But only one description makes sense for the values in the buffer.  How can we tell which description to use? InsertionRec InsertionRec StudentId StudentName DateOfBirth CourseCode Grant Gender InsertionRec InsertionRec StudentId StudentName DateOfBirth CourseCode Grant Gender StudentIdDeletionRec DeletionRec StudentId OldCourseCode NewCourseCode UpdateRec UpdateRec StudentId OldCourseCode NewCourseCode UpdateRec UpdateRec H E N N E S S Y R M L M F TransactionFile Buffer

The Transaction Type Code  Generally we cannot reliably establish the type of record READ into the buffer by examining its contents.  To allow us to distinguish between the record types, a special data item is inserted into each transaction which identifies the transaction type.  This data item is usually the first data item in the transaction record and one character in size, but it does not have to be.  Transaction types can be identified using a number, a letter or other character.

The Revised FD.  TransCode occurs in all the record descriptions.  How can we refer to the one in DeleteRec?  MOVE TransCode OF DeleteRec TO TCode.  But TransCode really only needs to be defined in one record.  Since all the records map on to the same area of storage the TransCode defined for the InsertionRec can be used no matter which record type is actually in the buffer. DATA DIVISION. FILE SECTION. FD TransactionFile. 01 InsertionRec. 02 TransCode PIC X. 02 StudentId PIC 9(7). 02 StudentName. 03 Surname PIC X(8). 03 Initials PIC XX. 02 DateOfBirth. 03 YOBirth PIC 9(2). 03 MOBirth PIC 9(2). 03 DOBirth PIC 9(2). 02 CourseCode PIC X(4). 02 Grant PIC 9(4). 02 Gender PIC X. 01 DeleteRec. 02 TransCode PIC X. 02 StudentId PIC 9(7). 01 UpdateRec. 02 TransCode PIC X. 02 StudentId PIC 9(7). 02 OldCourseCode PIC X(4). 02 NewCourseCode PIC X(4).

The Final FD. DATA DIVISION. FILE SECTION. FD TransactionFile. 01 InsertionRec. 88 EndOfTransFile VALUE HIGH-VALUES. 02 TransCode PIC X. 88 Insertion VALUE "I". 88 Deletion VALUE "D". 88 Update VALUE "U". 02 StudentId PIC 9(7). 02 StudentName. 03 Surname PIC X(8). 03 Initials PIC XX. 02 DateOfBirth. 03 YOBirth PIC 9(2). 03 MOBirth PIC 9(2). 03 DOBirth PIC 9(2). 02 CourseCode PIC X(4). 02 Grant PIC 9(4). 02 Gender PIC X. 01 DeleteRec. 02 FILLER PIC X(8). 01 UpdateRec. 02 FILLER PIC X(8). 02 OldCourseCode PIC X(4). 02 NewCourseCode PIC X(4).  TransCode and StudentId have the same description and are in the same location in all three records.  So they are defined only in the InsertionRec.  In the other records the area occupied by these two items is defined using FILLER.

 What happens when we display the OldCourseCode?  What happens if we now read an Update record into the buffer? InsertionRec InsertionRec TransCode StudentId StudentName DateOfBirth CourseCode Grant Gender InsertionRec InsertionRec TransCode StudentId StudentName DateOfBirth CourseCode Grant Gender FILLERDeletionRec DeletionRec FILLER OldCourseCode NewCourseCode UpdateRec UpdateRec FILLER OldCourseCode NewCourseCode UpdateRec UpdateRec I H E N N E S S Y R M L M F TransactionFile Buffer

 When a record smaller than the size of the largest record is read into the buffer any data that is not explicitly overwritten is left intact.  What happens when we display StudentName and DateOfBirth? InsertionRec InsertionRec TransCode StudentId StudentName DateOfBirth CourseCode Grant Gender InsertionRec InsertionRec TransCode StudentId StudentName DateOfBirth CourseCode Grant Gender FILLERDeletionRec DeletionRec FILLER OldCourseCode NewCourseCode UpdateRec UpdateRec FILLER OldCourseCode NewCourseCode UpdateRec UpdateRec U L M 6 1 L M 5 1 R M L M F TransactionFile Buffer

Printing a Report.  A report is made up of groups of printed lines of different types.  What types of line are required for the Student Details Report?  A program is required which will print a report.  The report, called the Student Details Report, will be based on the file Students.Dat.  The report will show the Name, StudentId, Gender and CourseCode of each student in the file.

Report Print Lines.  Page Heading. UL Student Details Report UL Student Details Report  Page Footing. Page : PageNum Page : PageNum  Column Headings. Student Id. Student Name Gender Course Student Id. Student Name Gender Course  Student Detail Line. StudentId. StudentName Gender CourseCode StudentId. StudentName Gender CourseCode  Report Footing. *** End of Student Details Report *** *** End of Student Details Report ***

Describing Print Lines. 01 PageHeading. 02 FILLER PIC X(7) VALUE SPACES. 02 FILLER PIC X(25) VALUE "UL Student Details Report". 01 PageFooting. 02 FILLER PIC X(19) VALUE SPACES. 02 FILLER PIC X(7) VALUE "Page : ". 02 FILLER PIC ColumnHeadings PIC X(36) VALUE " StudentId StudentName Gender Course". 01 StudentDetailLine. 02 PrnStudId PIC BB9(7). 02 PrnStudName PIC BBX(10). 02 PrnGender PIC BBBBX. 02 PrnCourse PIC BBBBX(4). 01 ReportFooting PIC X(38) VALUE "*** End of Student Details Report ***".  The Print Lines are all different record types!

The File Buffer  All data coming from, or going to, the peripherals must pass through a file buffer declared in the File Section.  The file buffer is associated with the physical device by means of a Select and Assign clause.  In previous lectures we saw that the file buffer is represented by a record description (01 level).  But the different types of line that must appear on our report are declared as different record types.  How can we declare these different record types in the File Section? ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT Printer ASSIGN TO “LPT1”. DATA DIVISION. FILE SECTION. FD Printer. 01 PrintLine. ????????????????

No VALUE clause in the FILE SECTION.  Defining a file buffer which is used by different record types is easy (as we have seen). But !!  These record types all map on to the same area of storage and print line records cannot share the same area of storage.  Why? Because most of the print line record values are assigned using the VALUE clause and these values are assigned as soon as the program starts.  To prevent us trying to use the VALUE clause to assign values to a File buffer COBOL has a rule which states that; In the FILE SECTION, the VALUE clause must be used in condition-name entries only (i.e. it cannot be used to give an initial value to an item).

A Solution  We define the print records in the WORKING-STORAGE SECTION.  We create a file buffer in the FILE SECTION which is the size of the largest print record.  We print a line by moving the appropriate print record to the file buffer and then WRITE ing the contents of the file buffer to the device. We get round the problem as follows;

ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT ReportFile ASSIGN TO “STUDENTS.RPT”. DATA DIVISION. FILE SECTION. FD ReportFile. 01 PrintLine PIC X(38). WORKING-STORAGE SECTION. 01 PageHeading. 02 FILLER PIC X(7) VALUE SPACES. 02 FILLER PIC X(25) VALUE "UL Student Details Report". 01 PageFooting. 02 FILLER PIC X(19) VALUE SPACES. 02 FILLER PIC X(7) VALUE "Page : ". 02 FILLER PIC ColumnHeadings PIC X(36) VALUE " StudentId StudentName Gender Course". 01 StudentDetailLine. 02 PrnStudId PIC BB9(7). 02 PrnStudName PIC BBX(10). 02 PrnGender PIC BBBBX. 02 PrnCourse PIC BBBBX(4). 01 ReportFooting PIC X(38) VALUE "*** End of Student Details Report ***". STUDENTS.RPT DISK

WRITE Syntax revisited.  When we are writing to a printer or a print file we use a form of the WRITE command different from that we use when writing to a sequential file.

ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT ReportFile ASSIGN TO "STUDENTS.RPT" ORGANIZATION IS LINE SEQUENTIAL. DATA DIVISION. FILE SECTION. FD ReportFile. 01 PrintLine PIC X(40). WORKING-STORAGE SECTION. 01 HeadingLine PIC X(21) VALUE " Record Count Report". 01 StudentTotalLine. 02 FILLER PIC X(17) VALUE "Total Students = ". 02 PrnStudentCount PIC Z,ZZ9. 01 MaleTotalLine. 02 FILLER PIC X(17) VALUE "Total Males = ". 02 PrnMaleCount PIC Z,ZZ9. 01 FemaleTotalLine. 02 FILLER PIC X(17) VALUE "Total Females = ". 02 PrnFemaleCount PIC Z,ZZ9. MOVE StudentCount TO PrnStudentCount MOVE MaleCount TO PrnMaleCount MOVE FemaleCount TO PrnFemaleCount WRITE PrintLine FROM HeadingLine AFTER ADVANCING PAGE WRITE PrintLine FROM StudentTotalLine AFTER ADVANCING 2 LINES WRITE PrintLine FROM MaleTotalLine AFTER ADVANCING 2 LINES WRITE PrintLine FROM FemaleTotalLine AFTER ADVANCING 2 LINES. STUDENTS.RPT DISK