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.

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

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.
- 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 
BY: JOSHUA THOMAS IGNATIUS TOWERS COBOL. Overview What is COBOL History Design Implementations What did it do Program structure Data types Syntax Sample.
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.
Screen Section Please use speaker notes for additional information!
Processing with VSAM Files Please use speaker notes for additional information!
COBOL for the 21 st Century Stern, Stern, Ley Chapter 1 INTRODUCTION TO STRUCTURED PROGRAM DESIGN IN COBOL.
Structured COBOL Programming, Stern & Stern, 9th Edition
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.
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)
Programming in COBOL-85 For IBM Mainframe System 390
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;
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.
Introduction to COBOL. COBOL  COBOL is an acronym which stands for Common Business Oriented Language.  The name indicates the target area of COBOL applications.
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 Examples to Accompany Structure Topic Please use speaker notes for additional information!
Programming in COBOL-85 For IBM Mainframe System 390 Jyothi Sridhar Kini E&R, Infosys Mail-id: Phone:
1 Interactive vs Batch Programs Cobol suited for developing both types of programs Interactive programs Accept input data from keyboard Input data processed.
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
1 The Procedure Division Chapter 4. 2 Main Two Sections File Section –Used to define files and record formats –Field names within records Working Storage.
Statement Syntax1 THE SELECT STATEMENT Purpose: designates a file and points to its physical location Syntax Definition : SELECT file-name-1 ASSIGN TO.
CPSC3111/CISM3111 COBOL Structured COBOL Programming Text: murach’s structured COBOL Authors: Murach, Prince, Menendez.
Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout.
Chapter 15 Introduction to PL/SQL. Chapter Objectives  Explain the benefits of using PL/SQL blocks versus several SQL statements  Identify the sections.
Any Questions!. Test Coming Up! Agenda Printing with Externally Described Printer Files Arrays.
COBOL Screens Please use speaker notes for additional information!
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.
Sort and Merge.  The StudentFile is a sequential file sequenced upon ascending StudentId.  Write a program to display the number of students taking.
Chapter 2 Using Variables and Constant. What is a Constant ? The data in COBOL programs falls in two broad categories: – Constants and Variables A constant.
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.
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)
1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.
IBM-Mainframes COBOL Class-1. Background and History  COBOL is an acronym for: Common Business Oriented Language  COBOL was developed in 1959 by the.
Module 1 1. Cobol Hierarchy Revised on COBOL Hierarchy There are four DIVISIONS:- IDENTIFICATION DIVISION. ENVIRONMENT DIVISION. DATA DIVISION.
Lecture 21 ENVIRONMENT DIVISION  defines files external to the program and devices.  contains two sections: 1.CONFIGURATION SECTION.  identifies computers.
Analysis of SAMPLE1.CBL Please check speaker notes for additional information!
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.
The PERFORM. The PERFORM Verb  Iteration is an important programming construct. We use iteration when we need to repeat the same instructions over and.
1 CSC103: Introduction to Computer and Programming Lecture No 27.
Computer Systems The Kingsway School. What are Computer Systems? Computer systems process data electronically Data is information which has no meaning.
Week 2/3 - 2nd Lecture Intro to COBOL Programming Defining Files and Processing Data.
Random update Please use speaker notes for additional information!
General Introduction Algorithms. Let’s write a program  A program is a collection of statements written in a language the computer understands.  A computer.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Programming in COBOL.
Designing and Debugging Batch and Interactive COBOL Programs
Topics Introduction to File Input and Output
Any Questions?.
Chapter 3 The DATA DIVISION.
Structured COBOL Programming
Chapter 14 Sorting and Merging.
Programming in COBOL-85 For IBM Mainframe System 390
CHAPTER 17 The Report Writer Module
Topics Introduction to File Input and Output
Programming in COBOL.
Presentation transcript:

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 are sometimes referred to as “data intensive” systems.  Generally, large volumes of data arise not because the data is inherently voluminous but because the same items of information have been recorded about a great many instances of the same object.

Files, Records, Fields.  We use the term FIELD to describe an item of information we are recording about an object (e.g. StudentName, DateOfBirth, CourseCode).  We use the term RECORD to describe the collection of fields which record information about an object (e.g. a StudentRecord is a collection of fields recording information about a student).  We use the term FILE to describe a collection of one or more occurrences (instances) of a record type (template).  It is important to distinguish between the record occurrence (i.e. the values of a record) and the record type (i.e. the structure of the record). Every record in a file has a different value but the same structure.

Files, Records, Fields. StudId StudName DateOfBirth COUGHLAN RYAN COFFEY O'BRIEN SMITH StudId StudName DateOfBirth COUGHLAN RYAN COFFEY O'BRIEN SMITH STUDENTS.DAT DATA DIVISION. FILE SECTION. FD StudentFile. 01 StudentDetails. 02 StudId PIC 9(7). 02 StudName PIC X(8). 02 DateOfBirth PIC X(8). DATA DIVISION. FILE SECTION. FD StudentFile. 01 StudentDetails. 02 StudId PIC 9(7). 02 StudName PIC X(8). 02 DateOfBirth PIC X(8). occurrences Record Type (Template)(Structure)

How files are processed.  Files are repositories of data that reside on backing storage (hard disk or magnetic tape).  A file may consist of hundreds of thousands or even millions of records.  Suppose we want to keep information about all the TV license holders in the country. Suppose each record is about 150 characters/bytes long. If we estimate the number of licenses at 1 million this gives us a size for the file of 150 X 1,000,000 = 150 megabytes.  If we want to process a file of this size we cannot do it by loading the whole file into the computer’s memory at once.  Files are processed by reading them into the computer’s memory one record at a time.

Record Buffers  To process a file records are read from the file into the computer’s memory one record at a time.  The computer uses the programmers description of the record (i.e. the record template) to set aside sufficient memory to store one instance of the record.  Memory allocated for storing a record is usually called a “record buffer”  The record buffer is the only connection between the program and the records in the file.

Record Buffers IDENTIFICATION DIVISION. etc. ENVIRONMENT DIVISION. etc. DATA DIVISION. FILE SECTION.ProgramRecordBuffer Declaration Declaration STUDENTS.DAT DISK Record Instance

Implications of ‘Buffers’  If your program processes more than one file you will have to describe a record buffer for each file.  To process all the records in an INPUT file each record instance must be copied (read) from the file into the record buffer when required.  To create an OUTPUT file containing data records each record must be placed in the record buffer and then transferred (written) to the file.  To transfer a record from an input file to an output file we will have to l read the record into the input record buffer l transfer it to the output record buffer l write the data to the output file from the output record buffer

Creating a Student Record 01StudentDetails.  Student Id.  Student Id. 02StudentId PIC 9(7).  Student Name.  Student Name. 02StudentName. Surname Surname 03 Surname PIC X(8). Initials Initials 03 Initials PIC XX.  Date of Birth  Date of Birth 02DateOfBirth. Year of Birth Year of Birth 03 YOBirthPIC 99. Month of Birth Month of Birth 03 MOBirthPIC 99. Day of Birth Day of Birth 03 DOBirthPIC 99.  Course Code  Course Code 02CourseCode PIC X(4).  Value of grant  Value of grant 02Grant PIC 9(4).  Gender  Gender 02Gender PIC X. 01StudentDetails.  Student Id.  Student Id. 02StudentId PIC 9(7).  Student Name.  Student Name. 02StudentName. Surname Surname 03 Surname PIC X(8). Initials Initials 03 Initials PIC XX.  Date of Birth  Date of Birth 02DateOfBirth. Year of Birth Year of Birth 03 YOBirthPIC 99. Month of Birth Month of Birth 03 MOBirthPIC 99. Day of Birth Day of Birth 03 DOBirthPIC 99.  Course Code  Course Code 02CourseCode PIC X(4).  Value of grant  Value of grant 02Grant PIC 9(4).  Gender  Gender 02Gender PIC X. Student Details.

Describing the record buffer in COBOL  The record type/template/buffer of every file used in a program must be described in the FILE SECTION by means of an FD (file description) entry.  The FD entry consists of the letters FD and an internal file name. DATA DIVISION. FILE SECTION. FD StudentFile. 01 StudentDetails. 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. DATA DIVISION. FILE SECTION. FD StudentFile. 01 StudentDetails. 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.

STUDENTS.DAT The Select and Assign Clause.  The internal file name used in the FD entry is connected to an external file (on disk or tape) by means of the Select and Assign clause. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT StudentFile ASSIGN TO “STUDENTS.DAT”. DATA DIVISION. FILE SECTION. FD StudentFile. 01 StudentDetails. 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. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT StudentFile ASSIGN TO “STUDENTS.DAT”. DATA DIVISION. FILE SECTION. FD StudentFile. 01 StudentDetails. 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. DISK

Select and Assign Syntax.  LINE SEQUENTIAL means each record is followed by the carriage return and line feed characters.  RECORD SEQUENTIAL means that the file consists of a stream of bytes. Only the fact that we know the size of each record allows us to retrieve them.

COBOL file handling Verbs  OPEN Before your program can access the data in an input file or place data in an output file you must make the file available to the program by OPENing it.  READ The READ copies a record occurrence/instance from the file and places it in the record buffer.  WRITE The WRITE copies the record it finds in the record buffer to the file.  CLOSE You must ensure that (before terminating) your program closes all the files it has opened. Failure to do so may result in data not being written to the file or users being prevented from accessing the file.

OPEN and CLOSE verb syntax  When you open a file you have to indicate to the system what how you want to use it (e.g. INPUT, OUTPUT, EXTEND) so that the system can manage the file correctly.  Opening a file does not transfer any data to the record buffer, it simply provides access.

The READ verb  Once the system has opened a file and made it available to the program it is the programmers responsibility to process it correctly.  Remember, the file record buffer is our only connection with the file and it is only able to store a single record at a time.  To process all the records in the file we have to transfer them, one record at a time, from the file to the buffer.  COBOL provides the READ verb for this purpose.

READ verb syntax  The InternalFilename specified must be a file that has been OPENed for INPUT.  The NEXT RECORD clause is optional and generally not used.  Using INTO Identifier clause causes the data to be read into the record buffer and then copied from there to the specified Identifier in one operation. l When this option is used there will be two copies of the data. It is the equivalent of a READ followed by a MOVE.

PERFORM UNTIL StudentRecord = HIGH-VALUES READ StudentRecords AT END MOVE HIGH-VALUES TO StudentRecord END-READ END-PERFORM. FrankCurtain LM051 StudentIDStudentName Course. StudentRecord FrankCurtain LM051 ThomasHealy LM068 TonyO‘Brian LM051 BillyDownes LM021 EOF How the READ works

Thomas Healy LM068 StudentIDStudentName Course. StudentRecord FrankCurtain LM051 ThomasHealy LM068 TonyO‘Brian LM051 BillyDownes LM021 EOF PERFORM UNTIL StudentRecord = HIGH-VALUES READ StudentRecords AT END MOVE HIGH-VALUES TO StudentRecord END-READ END-PERFORM. How the READ works

Tony O‘Brian LM051 StudentIDStudentName Course. StudentRecord FrankCurtain LM051 ThomasHealy LM068 TonyO‘Brian LM051 BillyDownes LM021 EOF PERFORM UNTIL StudentRecord = HIGH-VALUES READ StudentRecords AT END MOVE HIGH-VALUES TO StudentRecord END-READ END-PERFORM. How the READ works

BillyDownes LM021 StudentIDStudentName Course. StudentRecord FrankCurtain LM051 ThomasHealy LM068 TonyO‘Brian LM051 BillyDownes LM021 EOF PERFORM UNTIL StudentRecord = HIGH-VALUES READ StudentRecords AT END MOVE HIGH-VALUES TO StudentRecord END-READ END-PERFORM. How the READ works

StudentIDStudentName Course. StudentRecord FrankCurtain LM051 ThomasHealy LM068 TonyO‘Brian LM051 BillyDownes LM021 EOF HIGH-VALUES PERFORM UNTIL StudentRecord = HIGH-VALUES READ StudentRecords AT END MOVE HIGH-VALUES TO StudentRecord END-READ END-PERFORM. How the READ works

WRITE Syntax.  To WRITE data to a file move the data to the record buffer (declared in the FD entry) and then WRITE the contents of record buffer to the file.

FrankCurtain LM051 StudentIDStudentName Course. StudentRecordFrankCurtain LM051 EOF How the WRITE works OPEN OUTPUT StudentFile. MOVE " Frank Curtain LM051" TO StudentDetails. WRITE StudentDetails. MOVE " Thomas Healy LM068" TO StudentDetails. WRITE StudentDetails. CLOSE StudentFile. STOP RUN. OPEN OUTPUT StudentFile. MOVE " Frank Curtain LM051" TO StudentDetails. WRITE StudentDetails. MOVE " Thomas Healy LM068" TO StudentDetails. WRITE StudentDetails. CLOSE StudentFile. STOP RUN. Students.Dat

Thomas Healy LM068 StudentIDStudentName Course. StudentRecord FrankCurtain LM051 ThomasHealy LM068 EOF How the WRITE works OPEN OUTPUT StudentFile. MOVE " Frank Curtain LM051" TO StudentDetails. WRITE StudentDetails. MOVE " Thomas Healy LM068" TO StudentDetails. WRITE StudentDetails. CLOSE StudentFile. STOP RUN. OPEN OUTPUT StudentFile. MOVE " Frank Curtain LM051" TO StudentDetails. WRITE StudentDetails. MOVE " Thomas Healy LM068" TO StudentDetails. WRITE StudentDetails. CLOSE StudentFile. STOP RUN. Students.Dat

$ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. SeqWrite. AUTHOR. Team SarMag. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT StudentFile ASSIGN TO "STUDENTS.DAT" ORGANIZATION IS LINE SEQUENTIAL. DATA DIVISION. FILE SECTION. FD StudentFile. 01 StudentDetails. 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. PROCEDURE DIVISION. Begin. OPEN OUTPUT StudentFile. DISPLAY "Enter student details using template below. Enter no data to end.". PERFORM GetStudentDetails. PERFORM UNTIL StudentDetails = SPACES WRITE StudentDetails PERFORM GetStudentDetails END-PERFORM. CLOSE StudentFile. STOP RUN. GetStudentDetails. DISPLAY "NNNNNNNSSSSSSSSIIYYMMDDCCCCGGGGS". ACCEPT StudentDetails. $ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. SeqWrite. AUTHOR. Team SarMag. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT StudentFile ASSIGN TO "STUDENTS.DAT" ORGANIZATION IS LINE SEQUENTIAL. DATA DIVISION. FILE SECTION. FD StudentFile. 01 StudentDetails. 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. PROCEDURE DIVISION. Begin. OPEN OUTPUT StudentFile. DISPLAY "Enter student details using template below. Enter no data to end.". PERFORM GetStudentDetails. PERFORM UNTIL StudentDetails = SPACES WRITE StudentDetails PERFORM GetStudentDetails END-PERFORM. CLOSE StudentFile. STOP RUN. GetStudentDetails. DISPLAY "NNNNNNNSSSSSSSSIIYYMMDDCCCCGGGGS". ACCEPT StudentDetails.

$ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. SeqRead. AUTHOR. Team SarMag. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT StudentFile ASSIGN TO “STUDENTS.DAT” ORGANIZATION IS LINE SEQUENTIAL. DATA DIVISION. FILE SECTION. FD StudentFile. 01 StudentDetails. 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. PROCEDURE DIVISION. Begin. OPEN INPUT StudentFile READ StudentFile AT END MOVE HIGH-VALUES TO StudentDetails END-READ PERFORM UNTIL StudentDetails = HIGH-VALUES DISPLAY StudentId SPACE StudentName SPACE CourseCode READ StudentFile AT END MOVE HIGH-VALUES TO StudentDetails END-READ END-PERFORM CLOSE StudentFile STOP RUN. $ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. SeqRead. AUTHOR. Team SarMag. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT StudentFile ASSIGN TO “STUDENTS.DAT” ORGANIZATION IS LINE SEQUENTIAL. DATA DIVISION. FILE SECTION. FD StudentFile. 01 StudentDetails. 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. PROCEDURE DIVISION. Begin. OPEN INPUT StudentFile READ StudentFile AT END MOVE HIGH-VALUES TO StudentDetails END-READ PERFORM UNTIL StudentDetails = HIGH-VALUES DISPLAY StudentId SPACE StudentName SPACE CourseCode READ StudentFile AT END MOVE HIGH-VALUES TO StudentDetails END-READ END-PERFORM CLOSE StudentFile STOP RUN.