371 Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout John.

Slides:



Advertisements
Similar presentations
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)
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)
7-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)
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,
COBOL for the 21 st Century Stern, Stern, Ley Chapter 1 INTRODUCTION TO STRUCTURED PROGRAM DESIGN IN COBOL.
COBOL for the 21st Century
Structured COBOL Programming
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.
Structured COBOL Programming, Stern & Stern, 9th Edition
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)
Programming in COBOL-85 For IBM Mainframe System 390
12-1 Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout John.
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;
Programming Logic and Design Sixth Edition Chapter 2 Working with Data, Creating Modules, and Designing High-Quality Programs.
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)
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.
Chapter 2 Overview of C Part I J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National Taipei University.
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.
BIS 1753 Introduction to Computer Programming 1. Computer Program A set of instructions that enables a computer to process data Also called software Two.
7-1 Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout John.
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.
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.
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)
Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout.
1 The Data Division. 2 Main Two Sections File Section –Used to define files and record formats –Field names within records Working Storage Section –All.
1 IDENTIFICATION and ENVIRONMENT DIVISIONS. 2 Objectives Basic Structure of COBOL Programs General Coding and Formatting Rules Identification and the.
5-1 Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout John.
Structured Programming
7-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 CHAPTER 2 Cobol Language Fundamentals.
1 Chapter 9. To familiarize you with  Simple PERFORM  How PERFORM statements are used for iteration  Options available with PERFORM 2.
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)
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.
Module 1 1. Cobol Hierarchy Revised on COBOL Hierarchy There are four DIVISIONS:- IDENTIFICATION DIVISION. ENVIRONMENT DIVISION. DATA DIVISION.
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!
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.
Structured Programming
Designing and Debugging Batch and Interactive COBOL Programs
Any Questions?.
Chapter 3 The DATA DIVISION.
An Introduction to Structured Program Design in COBOL
Structured COBOL Programming
Presentation transcript:

371 Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout John Wiley & Sons, Inc. PowerPoint Winifred J. Rex Presentation Bowling Green State University 11th edition

37 2 The IDENTIFICATION and ENVIRONMENT DIVISIONs Modified by your instructor for pedagogical reasons only. Spring 2006 Chapter 2

373 Chapter Contents Basic Structure of a COBOL Program Coding Requirements of IDENTIFICATION DIVISION Sections of ENVIRONMENT DIVISION Assigning Files to Devices in ENVIRONMENT DIVISION

374 Basic COBOL Program Structure Originally, each COBOL instruction coded on single line of 80 characters Positions on line reserved for special purposes Rules may differ for your compiler Rigid column rules dropped in 2002+

375 Coding Rules Columns 1-6 and optional and rarely used today statement numbers; program-id… Column 7 for continuation, comment, starting new page Symbols are dash (-), asterisk (*) and slash (/) Columns 8-72 for COBOL program statements This is where NetExpress positions you.

376 Margin Rules Columns 8-72 divided into two areas Area A - columns 8, 9, 10, 11 Area B - columns Division, section and paragraph-names must all begin in Area A First letter of name must begin in column 8, 9, 10 or 11 Entry may extend into Area B

377 Margin Rules All other statements, clauses, and sentences begin anywhere in Area B (column 12, 13, 14, etc.) Select entries in ENVIRONMENT DIVISION Data description entries in DATA DIVISION All PROCEDURE DIVISION instructions Most will start in column 12!

378 Review of Margin Rules Division and Section Names Begin in Area A, end with a period Must appear on a line with no other entries Paragraph-names Begin in Area A, end with period followed by space May appear on line by themselves or with other entries Example: 2000-Wage-Routine.

379 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’.

3710 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.

3711 Review of Margin Rules Statements and Sentences Begin in Area B May appear on line by themselves or with other entries. Us: one statement per line Statements (e.g., OPEN, WRITE) may end with period but not recommended Sentences (e.g., a paragraph made up of one or more statements) end with period followed by space  The period is used to terminate a sentence. It terminates any conditional statement too, such as an IF, Read, some arithmetic statements, and a few other statements that may have conditional parts.  We now prefer Scope Terminators where practical.

3712 IDENTIFICATION DIVISION Provides identifying information about program Divided into paragraphs PROGRAM-ID only required paragraph Other paragraphs optional

3713 IDENTIFICATION DIVISION Format IDENTIFICATION DIVISION. PROGRAM-ID. program-name. [AUTHOR. [comment-entry] …] [other optional paragraphs]

3714 Backus-Normal Form (BNF) Brackets  optional Braces  chose from within Underlined  key word or special meaning Must include this entry (unless enclosed in brackets / braces. Once ‘inside’ the brackets and braces, if underlined word, must use.) Uppercase  Reserved Word. If used, must use as spelled. lower case  user/programmer-defined entry. ellipses  may repeat preceding item. All items may be nested!

3715 Understanding Instruction Formats Instruction formats describe syntax of all parts of COBOL language Describe required and optional elements, ordering and punctuation All formats in text are correct although additional options may be available

3716 Rules for Instruction Formats Uppercase words are COBOL reserved words Lowercase words are user-defined entries IDENTIFICATION DIVISION. PROGRAM-ID. program-name. DIVISION is reserved word program-name is user-defined data-name

3717 Rules for Instruction Formats Underlined words are required Punctuation if specified is required IDENTIFICATION DIVISION. PROGRAM-ID. program-name. IDENTIFICATION, DIVISION required PROGRAM-ID is required paragraph Periods required after division header, paragraph name and program-name Example

3718 Rules for Instruction Formats Brackets [ ] mean item is optional, braces { } mean one of enclosed items required Ellipses (...) mean entry may be repeated IDENTIFICATION DIVISION. PROGRAM-ID. program-name. [AUTHOR. [comment-entry] …] AUTHOR paragraph optional If included it may have any number of comment entries Example

3719 ENVIRONMENT DIVISION Describes files and computer devices used to process them Required by programs that process files This division is machine-dependent since devices differ from computer to computer  Is the only division that may change if program run on different computer

3720 Sections of Environment Division CONFIGURATION SECTION Describes computer used to compile/execute program Optional and recommended that you omit it Paragraphs: Source-Computer. Object- Computer; Special-Names are found in here.  INPUT-OUTPUT SECTION Describes input and output files and devices used by program Required for all programs using files

3721  INPUT-OUTPUT SECTION Follows CONFIGURATION SECTION (if coded) Includes FILE-CONTROL paragraph Contains one SELECT statement for each file used by program  Each SELECT defines a file-name and assigns device name to that file

3722 INPUT-OUTPUT SECTION Format INPUT-OUTPUT SECTION. Note: A-Margin FILE-CONTROL. SELECT file-name-1 ASSIGN TO implementor-name-1 [ORGANIZATION IS LINE SEQUENTIAL]. 1 Notice the indentation of the Select… Notice the syntax of the statement! 1 Use this clause for all PC files so each line treated as separate record.

3723 SELECT Statement file-names Choose meaningful file-names EMPLOYEE-FILE instead of E-FILE EMP-REPORT-FILE instead or OUT-FILE File-names are user-defined words Words chosen by programmer to represent some element of program Many call these ‘logical’ file names or ‘internal file names’ or programmer-defined file names… Must follow rules for forming user-define words

3724 Rules for User-Defined Words 1. 1 to 30 characters 2. Letters, digits, hyphens (-) only 3. No embedded blanks 4. At least one alphabetic character 5. May not begin or end with hyphen 6. May not be COBOL reserved word

3725 SELECT implementor-names Conventions for these names vary widely among computers Most enable use of special device names for frequently used devices Printer SYSLST, SYS$OUT, PRINTER Disk DISC or DISK and disk file-name In our class, we will merely use file names. Discuss:

3726 SELECT implementor-names Special device-names example Select Transaction-File Assign to "Data1.dat". Select Report-File Organization is Line Sequential Assign to “Outfile.dat” (will discuss) IBM Mainframe? Assign to ut-s-ddname or da-i-ddname etc.

3727 SELECT Statements for PCs For PCs, use device names specifying Drive on which file appears followed by a colon Folder name if file is in a folder (nested…) Name of file (See s on this) PC example Select Inventory-File Assign To "C:\Inventory\Inv-File.dat". Us: Assign to C:\cop2120\p1\broggio\pgm2.cbl”.

3728 ORGANIZATION clause for PCs This clause describes organization of records in the file Most PC disk files are created as text files Following data for each record, Enter key is pressed Indicates end of the line and end of the record If records 80 characters or less, each record appears on single line on screen or printer (Other ‘organizations’: Index, Relative,…)

3729 ORGANIZATION clause for PCs Include LINE SEQUENTIAL to Correctly read records from files when Enter key used to mark the end of each record Create disk files with each record followed by Enter key so each record appears on separate line when printed

3730 ORGANIZATION clause for PCs PC Example Select Sales-File Assign to "C:\Chapter2\Sales.dat" Organization is Line Sequential. (Our ‘path’ will be different, but format is same as above.)

3731  Coding Guidelines 1. Separate divisions by blank comment line, page eject symbol or blank line Us: Don’t use page eject. Will discuss. 2.Code a single statement per line 3.Code paragraph-names on line by themselves 4.Be liberal in use of comments. Box lengthy comments using asterisks.

3732  Coding Guidelines 5. Code SELECT statements in logical order (input files first, then output files) although order not required 6. Use separate lines for SELECT, ASSIGN, ORGANIZATION clauses for readability 7.Avoid use of device-specific file-names

3733 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’.

3734 PROCEDURE DIVISION. 100-MAIN-MODULE. 08OPEN INPUT EMPLOYEE-DATA 12OUTPUT PAYROLL-LISTING. PERFORM UNTIL ARE-THERE-MORE-RECORDS = ‘NO’ READ EMPLOYEE-DATA 16AT END 20MOVE ‘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. Discuss the indentation / use of tabs. …

3735 COBOL Changes Coding rules for Margins A and B will be recommended not required. Required PROGRAM-ID will be only paragraph in IDENTIFICATION DIVISION. All others can be specified as comments. Add Author paragraph and Date-Compiled. Length of user-defined words will be increased from 30 to 60 characters. Should never need that many!

3736 Chapter Summary IDENTIFICATION DIVISION Defines program name Program name up to eight characters, letters and digits only, acceptable on all computers PROGRAM-ID is only required paragraph, all others optional Use comments by coding an * in column 7

37 Chapter Summary ENVIRONMENT DIVISION Division is optional for COBOL 85 Not needed for fully interactive programs INPUT-OUTPUT SECTION required for any program using files Only machine-dependent division since device specification, file-name rules vary among computers