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.

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.
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)
Computer Programming Rattapoom Waranusast Department of Electrical and Computer Engineering Faculty of Engineering, Naresuan University.
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.
5-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 Logic and Design Fourth Edition, Introductory
Writing a Complete Program
Understanding the Mainline Logical Flow Through a Program (continued)
COBOL for the 21 st Century Stern, Stern, Ley Chapter 1 INTRODUCTION TO STRUCTURED PROGRAM DESIGN IN COBOL.
COBOL for the 21st Century
Exploring Microsoft Excel 2002 Chapter 8 Chapter 8 Automating Repetitive Tasks: Macros and Visual Basic for Applications By Robert T. Grauer Maryann Barber.
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)
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)
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)
Chapter To familiarize you with  Why COBOL is a popular business-oriented language.  Programming practices and techniques  History of COBOL.
1-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)
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)
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.
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!
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.
Designing and Debugging Batch and Interactive COBOL Programs Chapter 5.
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.
3-1 The DATA DIVISION Chapter Chapter Objectives To familiarize you with Systems design considerations Ways in which data is organized Rules for.
1 Interactive vs Batch Programs Cobol suited for developing both types of programs Interactive programs Accept input data from keyboard Input data processed.
14- 1 Chapter 14.  To familiarize you with ◦ How files may be sorted ◦ How to process file during SORT procedure  Before it is sorted  After it is.
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.
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.
CPSC3111/CISM3111 COBOL Structured COBOL Programming Text: murach’s structured COBOL Authors: Murach, Prince, Menendez.
9-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)
9-1 Iteration: Beyond the Basic PERFORM Chapter 9.
Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout.
12- 1 Chapter 12.  Single-Level OCCURS Clauses  Processing Data Stored in Array  Using OCCURS Clause for Table Handling  Use of SEARCH Statement 
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.
1 Chapter 9. To familiarize you with  Simple PERFORM  How PERFORM statements are used for iteration  Options available with PERFORM 2.
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.
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.
1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.
13- 1 Chapter 13.  Overview of Sequential File Processing  Sequential File Updating - Creating a New Master File  Validity Checking in Update Procedures.
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!
Chapter 4 PROCEDURE DIVISION. Paragraphs PROCEDURE DIVISION divided into paragraphs Each is independent module or routine Made up of series of instructions.
Week 2/3 - 2nd Lecture Intro to COBOL Programming Defining Files and Processing Data.
371 Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout John.
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.
Designing and Debugging Batch and Interactive COBOL Programs
Topics Introduction to File Input and Output
Chapter 3 The DATA DIVISION.
An Introduction to Structured Program Design in COBOL
Chapter 14 Sorting and Merging.
Iteration: Beyond the Basic PERFORM
CHAPTER 17 The Report Writer Module
Writing a Complete Program
Using screens and adding two numbers - addda.cbl
Topics Introduction to File Input and Output
Presentation transcript:

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 4. Write information to an output file 5. Accomplish end-of-job operations 6. Execute paragraphs from main module, return control to that main module 2

 IDENTIFICATION DIVISION ◦ Identifies program name  ENVIRONMENT DIVISION ◦ Defines files and equipment used by batch programs 3

 DATA DIVISION ◦ FILE SECTION  Detailed description of input/output records ◦ WORKING-STORAGE SECTION  Defines keyed input, displayed output  Defines fields needed for processing but not part of input/output records 4

Contains instructions to  Read data  Process data  Produce output  Perform end-of-job operations  You’ve used this division in lab already 5

 PROCEDURE DIVISION divided into paragraphs  Each is independent module or routine  Made up of series of instructions to perform specific set of operations  You will call these, not unlike a function or procedure in C++ 6

 Coded in Area A, followed by period  Follow rules for forming data-names except may be all digits ◦ 1010, 1020, 1030, etc. are valid paragraph names  Must be unique  Use good name, of course  Ok, what’s with the numbers ◦ No real purpose but knowing where it may be in code compared to other paragraphs ◦ PERFORM 1000−MAIN−ROUTINE THRU 1000−EXIT 7

 All statements coded in Area B  Statement begins with verb (ex. READ, MOVE)  Last statement in paragraph ends with period  Sentence - series of statements ending with period 8

 OPEN - to open files to be processed  PERFORM UNTIL … END-PERFORM ◦ Loop to continually READ and process input records and WRITE results to output file until there are no more records  CLOSE - to close files when done processing  STOP RUN - to end program 9

Accesses and makes files available for processing Identifies whether files will be used for input or output 10

INPUT file-name-1 … OPEN OUTPUT file-name-2 … File-names used must appear in SELECT statement File must be accessed with OPEN before reading from or writing to it 11 FORMAT

 May use a single OPEN statement Open Input Payroll-File Output PayChecks, Err-List  May use multiple OPEN statements Open Input Payroll-File Open Output PayChecks Open Output Err-List 12

PERFORM UNTIL condition-1 statement-1... [END-PERFORM]  Repeatedly executes statement(s) between PERFORM UNTIL … END-PERFORM until condition specified in UNTIL clause is met 13 FORMAT

 In typical batch program, instructions repeated until no more records in file  When condition met, program continues with statement following END-PERFORM 14

Perform Until WS-More-Data = 'NO' Read Payroll-File At End Move 'NO' To WS-More-Data Not At End Perform 200-Process-Record End-Read End-Perform 15 EXAMPLE

 Assume WS-More-Data initially = 'YES' ◦ Condition not met, so statements in PERFORM loop will be executed ◦ You can set this using the VALUE statement  WS-More-Data set to 'NO' when MOVE statement executed ◦ When condition checked again loop ends since condition has been met 16

 Reads record from file opened for input  Transfers record to input storage area  Makes one record available at a time, not entire file 17

 READ file-name-1 AT END statement-1 … [NOT AT END statement-2 …] [END-READ]  File-name appears in SELECT statement, FD entry and OPEN  AT END tests if there are more records 18 FORMAT

 If no more records ◦ Executes statement(s) after AT END ◦ Typically statement(s) to cause loop containing READ to end  If more records ◦ Reads in next record ◦ Executes statement(s) after NOT AT END ◦ Typically statement(s) to process record just read  Very intuitive 19

PERFORM paragraph-name  To execute instructions in separate paragraph or module one time  Transfers control to named paragraph  Executes all instructions in paragraph  Control returns to statement following PERFORM  Kind of like a procedure call in C++ 20 FORMAT

PERFORM paragraph-name UNTIL condition  Repeats paragraph until condition met  Control transfers to named paragraph  Executes instructions in paragraph and returns  Like calling a procedure in a loop in C++ 21 FORMAT

PERFORM UNTIL condition statement(s) END-PERFORM  Repeats statement(s) until condition met  Statement(s) to be executed are in-line, not in separate paragraph 22 FORMAT

 Steps performed after all records processed  Release all files  Terminate processing 23

 CLOSE file-name-1...  You should close all files opened  Indicates files no longer needed for processing  Releases files and deactivates devices 24 FORMAT

 May use a single CLOSE statement Close Payroll-File PayChecks Err-List  May use multiple CLOSE statements Close Payroll-File Close PayChecks Close Err-List 25

 Terminates the program  Usually last instruction in main module  Execution continues with next paragraph if STOP RUN is omitted  Will also close files if you didn’t 26

 DISPLAY to prompt for input  ACCEPT to store input in WORKING-STORAGE areas  Various statements to process input  DISPLAY to show output  DISPLAY to ask if there is more input  ACCEPT to get response  You’ve done this already 27

 Statements coded in an in-line PERFORM loop  Repeated until user responds that there is no more input  Like batch programs, loop may include simple PERFORM to execute instructions for processing input that are in a separate paragraph 28

 MOVE identifier-1 TO identifier-2  Copies contents of identifier-1 to identifier-2  Like the assignment operator ‘ = ‘ in C++ 29 FORMAT

 WRITE record-name-1  Transmits data from output record area to associated file on device specified  Record-name is 01 level name following FD for a file opened for output  READ file-name, WRITE record-name  Notice that we are working with the entire record, not a field. Different that what you are used to. 30 FORMAT

 Start with asterisk (*) in column 7 (officially)  Use as reminders and explanations of processing performed by program  Use to describe program in IDENTIFICATION DIVISION  Use to describe each module in PROCEDURE DIVISION  Looks like we just put the * in the 1 st column 31

 Programs that process large quantity of data stored in files  Require ENVIRONMENT DIVISION  Require FILE SECTION in DATA DIVISION  Use OPEN, READ, WRITE, CLOSE verbs to process files 32

 Programs that process individual items rather than large group of items  Provide quick solution to ACCEPT data, process it and DISPLAY results 33

 Batch Program Structure ◦ Main module's in-line PERFORM UNTIL repeatedly executes READ statement ◦ READ gets and processes next record until there are no more ◦ Files are opened before PERFORM loop and closed after loop ends 34

 Interactive Program Structure ◦ Main module's in-line PERFORM UNTIL repeatedly  Prompts user for input and accepts it  PERFORMs other paragraphs as needed to process input  Asks user if there is more input ◦ Loop repeats until user indicates there is no more data 35

 Paragraph-names coded in Area A and end with period  All other PROCEDURE DIVISION statements coded in Area B  Statements executed in order unless ◦ PERFORM UNTIL loop executes ◦ PERFORM transfers control to another paragraph 36