Programming in COBOL-85 For IBM Mainframe System 390 Jyothi Sridhar Kini E&R, Infosys Mail-id: Phone: 52179.

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

Module 7 Sorting.  The StudentFile is a sequential file sequenced upon ascending StudentId.  How to sort the file by StudentId? DATA DIVISION. FILE.
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.
Introduction to C Programming
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.
File Management Chapter 12. File Management A file is a named entity used to save results from a program or provide data to a program. Access control.
METU Department of Computer Eng Ceng 302 Introduction to DBMS Disk Storage, Basic File Structures, and Hashing by Pinar Senkul resources: mostly froom.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 13 Disk Storage, Basic File Structures, and Hashing.
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.
Structured COBOL Programming, Stern & Stern, 9th Edition
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)
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.
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.
File Organization Techniques
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.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 17 Disk Storage, Basic File Structures, and Hashing.
A Simple Two-Pass Assembler
History COBOL (Common Business Oriented Language) was one of the earliest high-level programming languages. COBOL was first proposed in 1959 by the Conference.
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.
Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 6: Sequential Data Files.
Lecture 31 Numeric Edited Alphabetic (A) AlphaNumeric (X) Numeric (9, V, S) Numeric Edited (9, Z, comma, decimal point, minus sign) –Z = zero suppressed.
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.
Operating Systems (CS 340 D) Dr. Abeer Mahmoud Princess Nora University Faculty of Computer & Information Systems Computer science Department.
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
Chapter 9 I/O Streams and Data Files
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.
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)
Statement Syntax1 THE SELECT STATEMENT Purpose: designates a file and points to its physical location Syntax Definition : SELECT file-name-1 ASSIGN TO.
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.
13-1 Sequential File Processing Chapter Chapter Contents Overview of Sequential File Processing Sequential File Updating - Creating a New Master.
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.
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.
FILE ORGANIZATION.
Analysis of SAMPLE1.CBL Please check speaker notes for additional information!
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.
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!
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.
( ) 1 Chapter # 8 How Data is stored DATABASE.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
Chapter 6: Sequential Data Files
Designing and Debugging Batch and Interactive COBOL Programs
FILE ORGANIZATION.
Topics Introduction to File Input and Output
Chapter 3 The DATA DIVISION.
Chapter 14 Sorting and Merging.
Programming in COBOL-85 For IBM Mainframe System 390
A Simple Two-Pass Assembler
CHAPTER 17 The Report Writer Module
Please use speaker notes for additional information!
Topics Introduction to File Input and Output
Presentation transcript:

Programming in COBOL-85 For IBM Mainframe System 390 Jyothi Sridhar Kini E&R, Infosys Mail-id: Phone: 52179

Objectives of the Session (1) Introduction to File handling. (2) File ORGANIZATION and ACCESS methods. (3) File handling verbs. (4) Sequential File processing. (5) Demonstration of sample programs.

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.

Introduction to File processing  Field Field type and Field size.  Record Record-Size, Fixed length records and Variable length records.  File Master files, Transaction files, File organization and File access method. Basic Terminologies

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 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)

Example REGNO NAME AGE KA101 JYOTHI 19 KA102 ANIRUDH 20 KA103 SRIDHAR 18 Field-1 File Field-2 Field-3 Record-1 Record-2 Record-3 STUDENT

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 DISK Record Instance

Description of a Record buffer for a file containing Single record type DATA DIVISION. FILE SECTION. FD STUDFILE. 01 STUD-REC. 05 REGNO PIC X(5). 05 NAME PIC A(15). 05 AGE PIC 9(2). Record Buffer and its implications

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.

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 – read the record into the input record buffer – transfer it to the output record buffer – write the data to the output file from the output record buffer

Description of a Record buffer for a file containing Multiple record types DATA DIVISION. FILE SECTION. FD TRANS-FILE. 01 INS-REC. 05 T-CODEPIC X. 05 REGNOPIC X(5). 05 NAMEPIC A(15). 05 AGEPIC 9(2). 01 DEL-REC. 05 T-CODEPIC X. 05 REGNO PIC X(5). 01 UPD-REC. 05 T-CODEPIC X. 05 REGNO PIC X(5). 05 AGE PIC 9(2). Record Buffer and its implications

Organization and Access  Two important characteristics of files are – DATA ORGANIZATION – METHOD OF ACCESS  Data organization refers to the way the records of the file are organized on the backing storage device. COBOL recognizes three main file organizations; – Sequential- Records organized serially. – Relative - Relative record number based organization. – Indexed- Index based organization.  The method of access refers to the way in which records are accessed. – A file with an organization of Indexed or Relative may still have its records accessed sequentially. – But records in a file with an organization of Sequential can not be accessed directly.

Sequential Organization  The simplest COBOL file organization is Sequential.  In a Sequential file the records are arranged serially, one after another, like cards in a dealing show.  In a Sequential file the only way to access any particular record is to; Start at the first record and read all the succeeding records until you find the one you want or reach the end of the file.  Sequential files may beOrdered or Unordered Unordered (these should be called Serial files)  The ordering of the records in a file has a significant impact on the way in which it is processed and the processing that can be done on it.

Sequential file organization  Simplest and least flexible of all types of file organizations.  Can only be accessed sequentially.  Records can be only added to the end of the file.  Does not provide means to insert or delete records.  Most storage efficient.

FILE-CONTROL paragraph for sequential files SELECT file-name ASSIGN TO implementor-name [ ORGANIZATION IS SEQUENTIAL ] [ ACCESS MODE IS SEQUENTIAL] [ FILE STATUS IS identifier ].

STUDENTS 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”. 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”. 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

FD entries for Fixed length records FD file-name [ RECORD CONTAINS integer-1 CHARACTERS ] [ BLOCK CONTAINS integer-2 { RECORDS, CHARACTERS }] [ LABEL { RECORD IS, RECORDS ARE } { STANDARD,OMITTED }] [ DATA { RECORD IS, RECORDS ARE } identifier-1, identifier-2,... ]

FD entries for Variable length records FD file-name [ RECORD CONTAINS integer-1 TO integer-2 CHARACTERS ] [ BLOCK CONTAINS integer-3 TO integer-4 CHARACTERS ] [ LABEL { RECORD IS, RECORDS ARE } { STANDARD, OMITTED }] [ DATA { RECORD IS, RECORDS ARE } identifier-1, identifier-2,... ]

File handling verbs  OPEN  READ  WRITE  REWRITE  CLOSE

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.

OPEN verb  Syntax OPEN {INPUT, OUTPUT, I-O, EXTEND} Filename-1... OPEN MODE STATEMENT INPUT OUTPUT I-O EXTEND READ WRITE REWRITE

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. – When this option is used there will be two copies of the data. It is the equivalent of a READ followed by a MOVE.

Working of the READ statement STUD-REC 101J YOTHI 25BU REGNONAMEAGE 13AHN2B EOF 12IHA2B 0RCA0U 0NTY2U A STUDENT PERFORM UNTIL STUD-REC = HIGH-VALUES READ STUDFILE AT END MOVE HIGH-VALUES TO STUD-REC END-READ END-PERFORM.

Working of the READ statement STUD-REC 101J Y OTHI25BU REGNONAMEAGE 13AHN2B EOF 12IHA2B 0RCA0U 0NTY2U A STUDENT 101J Y O TH I25BU PERFORM UNTIL STUD-REC = HIGH-VALUES READ STUDFILE AT END MOVE HIGH-VALUES TO STUD-REC END-READ END-PERFORM.

Working of the READ statement 101JYOTHI25BU REGNONAMEAGE 13AHN2B EOF 0RCA0UA 102NITHYA22BU 102NITHYA22BU PERFORM UNTIL STUD-REC = HIGH-VALUES READ STUDFILE AT END MOVE HIGH-VALUES TO STUD-REC END-READ END-PERFORM. STUD-REC STUDENT

Working of the READ statement 101JYOTHI25BU REGNONAMEAGE EOF 103RACHAN20BU 102NITHYA22BU A 103RACHAN20BUA PERFORM UNTIL STUD-REC = HIGH-VALUES READ STUDFILE AT END MOVE HIGH-VALUES TO STUD-REC END-READ END-PERFORM. STUD-REC STUDENT

Working of the READ statement 101J YO THI25BU REGNONAMEAGE EOF 102NITHYA22BU 103RACHAN20BUA PERFORM UNTIL STUD-REC = HIGH-VALUES READ STUDFILE AT END MOVE HIGH-VALUES TO STUD-REC END-READ END-PERFORM. STUD-REC STUDENT

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

Working of the WRITE statement STUD-REC 101JYOTHI25BU REGNONAMEAGE EOF 101JYOTH I 25U MOVE “BU101JYOTHI 25” TO STUD-REC. WRITE STUD-REC. MOVE “BU102NITHYA 22” TO STUD-REC. WRITE STUD-REC. B STUDENT

Working of the WRITE statement REGNONAMEAGE EOF 102NITHYA22BU 102NITHYA22BU 101JYOT H I25UB STUD-REC STUDENT MOVE “BU101JYOTHI 25” TO STUD-REC. WRITE STUD-REC. MOVE “BU102NITHYA 22” TO STUD-REC. WRITE STUD-REC.

REWRITE verb REWRITE is used to update an existing record in the file Syntax REWRITE record-name [ FROM identifier-1 ] Note: The REWRITE statement can only be used if the file is opened in the I-O mode and its execution must be preceded by the successful READ statement on the file. The REWRITE statement replaces last read record

CLOSE verb  Syntax CLOSE filename1  Releases the named files from the program.  If a file is stored on a magnetic tape, after the execution of the CLOSE statement the tape is rewound.  Is optional for COBOL- 85.

Sequential files - A Final Look Advantages Slow - when the hit rate is low. Complicated to change (insert, delete). Fast - when the hit rate is high. Most storage efficient. Simple organization. Dis-advantages

Review  Introduction to File handling.  File ORGANIZATION and ACCESS methods.  File handling verbs.  Sequential File processing

Review questions  If there are 15 records to be read, the __________ attempt to read a record causes an AT END condition to be executed  READ statement should be followed by __________  Write statement should be followed by ____________  Which of the following does not appear in the DATA DIVISION – REDEFINES – JUSTIFIED – SELECT  WRITE statement cannot be used when a file opened in EXTEND mode (True / False) sixteenth File name Record name

Any Questions ????

Thank you Jyothi Sridhar Kini E&R, Infosys Mail-id: Phone: 52179