1 Interactive vs Batch Programs Cobol suited for developing both types of programs Interactive programs Accept input data from keyboard Input data processed.

Slides:



Advertisements
Similar presentations
2-1 Chapter 2.  Coding Requirements of IDENTIFICATION DIVISION  Sections of ENVIRONMENT DIVISION  Assigning Files to Devices in ENVIRONMENT DIVISION.
Advertisements

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)
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)
Introductory Remarks. COURSE OBJECTIVES: (TAKEN FROM PREFACE) 1. To teach students how to design programs so that they are easy to read, debug, adapt,
COSC 120 Computer Programming
Modules, Hierarchy Charts, and Documentation
Understanding the Mainline Logical Flow Through a Program (continued)
Pseudocode.
COBOL for the 21 st Century Stern, Stern, Ley Chapter 1 INTRODUCTION TO STRUCTURED PROGRAM DESIGN IN COBOL.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 1 Introduction.
Pseudocode.
Programming Logic and Design Fourth Edition, Introductory
Basic Elements of C++ Chapter 2.
COBOL for the 21st Century
Computer Science 101 Introduction to Programming.
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)
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)
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.
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)
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)
Modifications to program Addda.cbl Please use speaker notes for additional information!
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.
Programming Examples to Accompany Structure Topic Please use speaker notes for additional information!
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.
CS CS Computing for Business Instructor:David Tucker GTA:Batul Mirza.
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
Initial Steps in Program Development [Using problem defined in Ch. 1 of Stern & Stern]
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.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout.
1 IDENTIFICATION and ENVIRONMENT DIVISIONS. 2 Objectives Basic Structure of COBOL Programs General Coding and Formatting Rules Identification and the.
Algorithms  Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
11- 1 Chapter 11.  Avoiding Logic Errors by Validating Input  What to Do If Input Errors Occur  Global Considerations in COBOL  When Data Should Be.
Structured Programming
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.
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.
IBM-Mainframes COBOL Class-1. Background and History  COBOL is an acronym for: Common Business Oriented Language  COBOL was developed in 1959 by the.
13- 1 Chapter 13.  Overview of Sequential File Processing  Sequential File Updating - Creating a New Master File  Validity Checking in Update Procedures.
Analysis of SAMPLE1.CBL Please check speaker notes for additional information!
11- 1 Chapter 11.  Avoiding Logic Errors by Validating Input  What to Do If Input Errors Occur  Global Considerations in COBOL  When Data Should Be.
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.
16- 1 Chapter 16.  To familiarize you with  COPY statement for copying parts of a program stored in a library  CALL statement for executing called.
Structured Programming
Keyboard Input and Screen Display ––––––––––– Interactive Programming
Designing and Debugging Batch and Interactive COBOL Programs
Any Questions?.
Chapter 3 The DATA DIVISION.
An Introduction to Structured Program Design in COBOL
Chapter 14 Sorting and Merging.
Chapter 4: Writing and Designing a Complete Program
Presentation transcript:

1 Interactive vs Batch Programs Cobol suited for developing both types of programs Interactive programs Accept input data from keyboard Input data processed immediately Output (results) displayed on screen immediately

2 Interactive vs Batch Programs Batch programs Process large volumes of input at periodic intervals Input data read in from files Output written to files Can be files on disk, print files, files to be transmitted to a remote location: but files.

3 Files, Records, Fields Field – a single data item: your name; salary; Record – everything to do with a specific topic, such as all the information about YOU to generate your pay check: Your name, ssan, deductions, address, bank account number, hours worked, overtime hours…. File – The grouping of individual records of all employees working in a corporation for whom you want to generate a pay check. Typically read a single record, prepare the output, read next record, and continue until EOF. Book definitions: p. 21

4 Overview of the Four Divisions Every COBOL program contains up to four separate divisions in the following order: IDENTIFICATION DIVISION ENVIRONMENT DIVISION DATA DIVISION PROCEDURE DIVISION

5 Overview of the Four Divisions IDENTIFICATION DIVISION Identifies program to operating system Provides documentation about program ENVIRONMENT DIVISION Defines file-names Describes devices used to store them Not included in fully interactive programs

6 Overview of the Four Divisions DATA DIVISION Describes input and output format of data in files Defines any constants and work areas PROCEDURE DIVISION Contains instructions to read input, process it and create output

7 Sample Interactive Program Purpose to compute employee WAGES Input from keyboard HOURS and RATE Processing compute WAGES as HOURS x RATE Output displayed on screen WAGES

8 Sample Interactive Program IDENTIFICATION DIVISION One required entry, PROGRAM-ID Names the program DATA DIVISION Describes and defines storage for all data Data defined in WORKING-STORAGE SECTION for interactive program

9 IDENTIFICATION DIVISION. PROGRAM-ID. CH0102. DATA DIVISION. WORKING-STORAGE SECTION. 01 SALES-AMOUNT PIC 999V SALES-TAX PIC Fields; sizes; numeric 01 MORE-DATA PIC XXX VALUE 'YES'. Field; alphanumeric PROCEDURE DIVISION.instructions: operate on data 100-MAIN. PERFORM UNTIL MORE-DATA = 'NO' DISPLAY 'ENTER SALES AMOUNT AS DOLLARS AND CENTS' ACCEPT SALES-AMOUNTreads / accepts from keyboard COMPUTE SALES-TAX = SALES-AMOUNT *.08 DISPLAY SALES-TAXwrites to keyboard DISPLAY 'IS THER MORE INPUT (YES OR NO)?‘ prompts user ACCEPT MORE-DATAaccepts keyboard input END-PERFORM STOP RUN. Sample COBOL Program – Interactive (no Environment Division)

10 Data Defined in Sample Program Keyed input fields (HOURS, RATE) Output fields (WAGES) Other fields used for processing (MORE- DATA) Wages (not shown) 01 WAGESPIC

11 PICTURE Clause 01 level begins definition of each field much more later on this… 01 has special significance. PICTURE or PIC clause describes Type of data Numeric (PIC 9) Nonnumeric (PIC X) (alphanumeric) Size of field - determined by number of 9’s or X’s

12 PICTURE Clauses RATE with PIC 99V99 includes V to show assumed decimal point position User enters data with decimal point Program uses V to align data WAGES includes actual decimal point Shown when value displayed on screen Wages (not shown) 01 WAGESPIC

13 Giving Field Initial Value MORE-DATA with PIC XXX is nonnumeric field Assigned initial contents of YES by use of VALUE clause Value must be in quotation marks since MORE-DATA is nonnumeric field

14 PROCEDURE DIVISION Set of instructions to be executed by program Organization of instructions planned before coding begins Pseudo-code, an English-like description of program instructions, used for planning Describes program logic and order in which instructions will be executed

15 PROCEDURE DIVISION PROCEDURE DIVISION includes one paragraph 100- MAIN Note: program here is horribly simple, as we would expect at this time. There is only one paragraph (module) and a structure chart (architectural design) is almost meaningless – would contain a single box… List of instructions that follow make up paragraph Period follows last statement in paragraph (STOP RUN.) Main processing controlled by PERFORM … END- PERFORM loop END-PERFORM is called a ‘scope terminator.’ VERY important!

16 PERFORM … END-PERFORM Repeats set of instructions as long as user enters YES in response to prompt "IS THERE MORE DATA (YES/NO)?" MORE-DATA initially contains YES so instructions in loop executed first time

17 PERFORM … END-PERFORM When user enters NO as response MORE-DATA set to "NO" and loop ends After loop, STOP RUN is executed, ending program (Note the indentation of code within the loop. This is essential to good programming style!)

18 PERFORM … END-PERFORM Statements in loop executed in order they are listed DISPLAY displays value in quotes or value of field on screen ACCEPT stores value user enters from keyboard in field MULTIPLY performs calculation to find WAGES

19 Sample Batch Program In batch mode, data comes from input file instead of keyboard Data for each employee stored in a record in file on disk (see page 21) Employee name, hours and rate data called fields

20 Sample Batch Program Calculated results (Wages) stored in file instead of displayed on screen (but can be both displayed as well as stored in a For each input record Record created and stored in output file Includes employee name, hours, rate and computed wages File intended for printing so spacing added between fields for readability I disagree. Most input data is NOT spaced for printing!!! Fields are all contiguous for important reasons! (will discuss)

21 COBOL Divisions All four divisions included for batch programs IDENTIFICATION DIVISION first with required PROGRAM-ID paragraph ENVIRONMENT DIVISION CONFIGURATION SECTION – not required. INPUT-OUTPUT SECTION assigns input and output files to specific devices. required to name (called logical file names or programmer-defined file names) files and associate them with specific devices, such as a CD or disk or …

22 DATA DIVISION (will be repeating this many times) FILE SECTION describes format of input and output files Characteristics of the file itself Characteristics of the records and their fields. Fields in records described using PICTURE clause Decimal point not stored in input records Use V for ‘implied decimal’ for alignment Use actual decimal point for fields in output record so it is printed

23 PROCEDURE DIVISION Contains instructions to be executed by computer Instructions executed in order they appear Includes two paragraphs with period at end of each. Let’s consider the program in your textbook. This is also assignment #1 to be turned in later. First, let’s overview…

24 IDENTIFICATION DIVISION. PROGRAM-ID. SAMPLE AUTHOR. YOUR-NAME-PLEASE. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT EMPLOYEE-DATA ASSIGN TO EMP-DAT. SELECT PAYROLL-LISTING ASSIGN TO PRINTER. DATA DIVISION. FILE SECTION. FDEMPLOYEE-DATA. 01EMPLOYEE-RECORD. 05EMPLOYEE-NAME-INPIC X(20). 05HOURS-WORKED-INPIC HOURLY-RATE-INPIC 9V99. FDPAYROLL-LISTING. 01PRINT-REC. 05PIC X(20). 05NAME-OUTPIC X(20). 05PIC X(10). 05HOURS-OUTPIC PIC X(8). 05RATE-OUTPIC PIC XXXXXX. 05WEEKLY-WAGES-OUTPIC WORKING-STORAGE SECTION. 01ARE-THERE-MORE-RECORDSPIC XXX VALUE ‘YES’.

25 PROCEDURE DIVISION. 100-MAIN-MODULE. OPEN INPUT EMPLOYEE-DATA OUTPUT PAYROLL-LISTING. PERFORM UNTIL ARE-THERE-MORE-RECORDS = ‘NO’ READ EMPLOYEE-DATA AT END MOVE ‘NO’ TO ARE-THERE-MORE-RECORDS NOT AT END PERFORM 200-WAGE-ROUTINE END-READ END-PERFORM CLOSE EMPLOYEE-DATA PAYROLL-LISTING STOP RUN. 200-WAGE-ROUTINE. MOVE SPACES TO PRINT-REC MOVE EMPLOYEE-NAME-IN TO NAME-OUT MOVE HOURS-WORKED-IN TO HOURS-OUT MOVE HOURLY-RATE-IN TO RATE-OUT MULTIPLY HOURS-WORKED-IN BY HOURLY-RATE-IN GIVING WEEKLY-WAGES-OUT WRITE PRINT-REC. OBSERVE INPUT AND OUTPUT ON P. 24.

MAIN-MODULE OPENs files to be used by program Repeatedly READs in records (PERFORM … END-PERFORM) until there are no more Calls second paragraph 200-WAGE- ROUTINE to process each record CLOSEs files after all records read Ends program (STOP RUN)

27 READ Statement Reads one record into program storage area Record must be in storage to use it Entire record ‘read into’ the Process Area (the 01 area) Takes one of two actions depending on whether record was read

28 READ Statement - 1 PERFORM instruction after NOT AT END executed when a successful read occurs: Statements in paragraph 200-WAGE-ROUTINE executed to process record Control remains within the Perform. Condition is evaluated and is false, so the loop iterates.

29 READ Statement - 2 If no more records are available, MOVE instruction after AT END executed 'NO ' moved to ARE-THERE-MORE- RECORDS, ends loop Control returns to the Perform which determines that the condition is now True and control passes to the statement following the Perform.

WAGE-ROUTINE First MOVE initializes PRINT-REC to blanks Then MOVEs name, hours, wages to output fields Calculates WAGES with MULTIPLY statement, MOVES it to output field WRITEs data in employee output record to print file

31  Entering & Running a Program To type in and run a COBOL program on your computer system, you need to know how to: Log on and off of the computer Name COBOL files on the computer Use a text editor to key in, modify and save files Compile a COBOL source program to translate it into machine language Link or load the object program Run the object program

32 COMMENTS1 Interactive Programs don’t need Environment Division Batch Programs Need all four divisions – in order Environment Division names / associates files with devices. machine / implementation dependent. Assign to clauses will differ (will inform you…)

33 COMMENTS2 Data Division will always have a File Section describes the file in general and the records with their fields in particular. Provides the sizes and classification of fields and relative placement of data in input and output records All data fields are named! (Constants {later} are treated separately) All fields must be defined with their sizes and type of data expected. Name files with meaningful names.

34 COMMENTS3 Filler – reserved word Many reserved words – have special meanings. ARE-THERE-MORE-RECORDS is really a flag field. I prefer EOF. Will discuss more later. types of data: numeric pic 9 alphanumeric pic x (non-numeric) alphabetic pic A (not used much anymore). Data name rules – later Editing characters (decimals, commas…) later.