1 IDENTIFICATION and ENVIRONMENT DIVISIONS. 2 Objectives Basic Structure of COBOL Programs General Coding and Formatting Rules Identification and the.

Slides:



Advertisements
Similar presentations
DT266/2 COBOL Basics – Declaring Data Basic Operations.
Advertisements

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)
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)
CHAPTER 1: AN OVERVIEW OF COMPUTERS AND LOGIC. Objectives 2  Understand computer components and operations  Describe the steps involved in the programming.
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)
COBOL for the 21 st Century Stern, Stern, Ley Chapter 1 INTRODUCTION TO STRUCTURED PROGRAM DESIGN IN COBOL.
Programming Logic and Design Fourth Edition, Introductory
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
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)
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.
Fortran 1- Basics Chapters 1-2 in your Fortran book.
Chapter To familiarize you with  Why COBOL is a popular business-oriented language.  Programming practices and techniques  History of COBOL.
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.
BIS 1753 Introduction to Computer Programming 1. Computer Program A set of instructions that enables a computer to process data Also called software Two.
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.
UNIT 1 UNIT 1 Stephen S. Linkin Houston Community College System 8/28/ Copywrite © Houston Community College System 2007 Graphics Courtesy of IBM.
1 Interactive vs Batch Programs Cobol suited for developing both types of programs Interactive programs Accept input data from keyboard Input data processed.
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.
Programming Fundamentals. Today’s Lecture Why do we need Object Oriented Language C++ and C Basics of a typical C++ Environment Basic Program Construction.
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.
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.
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.
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.
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.
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.
Any Questions? Week 1 - 2nd Lecture Intro to COBOL Programming Defining Files and Processing Data.
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.
1 Project 7: Looping. Project 7 For this project you will produce two Java programs. The requirements for each program will be described separately on.
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.
CSC201: Computer Programming
© 2016 Pearson Education, Ltd. All rights reserved.
Structured Programming
Programming in COBOL.
Designing and Debugging Batch and Interactive COBOL Programs
Chapter 3 The DATA DIVISION.
An Introduction to Structured Program Design in COBOL
Structured COBOL Programming
Programming in COBOL-85 For IBM Mainframe System 390
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
CHAPTER 17 The Report Writer Module
Language Translation Issues
Language Translation Issues
Introduction to C Programming
Decision Making Using the IF and EVALUATE Statements
Presentation transcript:

1 IDENTIFICATION and ENVIRONMENT DIVISIONS

2 Objectives Basic Structure of COBOL Programs General Coding and Formatting Rules Identification and the Environment Divisions – –Old and new.

3 Divisions in a COBOL Program IDENTIFICATION DIVISION –Identifies your program to the computer –Provides a program-id and other optional information describing your program ENVIRONMENT DIVISION –Describes the environment within which your program must operate. –Sets up relationships (Select statement) between your physical files on disk and your program-name (logical name) for these files within your program. DATA DIVISION –Describes all input and output files and their formats –Describes all supporting working areas such as tables, print lines, counters, accumulators, and similar independent items. PROCEDURE DIVISION –Contains the program logic of your program – your instructions. Sequence, Selection, Iteration statements

4 Programming Area in Net Express Each line holds about 80 columns room for around twenty statements Each line ‘should’ contain a single COBOL entry (instruction, data…) Positions 1-6 and will not be used in this course. Columns 1-6 were used to enter statement numbers; columns were used to enter a program-id Column 7: Very useful: Placing an asterisk (*) in column 7 causes the compiler to treat the entire line as a comment. These are used a lot to internally document your program. Use of a dash ‘-’ in column 7 can be used to indicate the the continuation of a nonnumeric literal (a string of characters). A slash (/) in column 7 (only entry in line) causes the source program listing to be continued on the next page if you are seeking hard copy listing of your program. Nice for printing different modules on separate pages.

5 Main Coding Areas Area A (column 8-11):. All division, section, and paragraph entries should start within this area. Clearly these may extend beyond column 11. Area B (column 12-72):. All statements and sentences must start in this area A number of other program entries will start in column 12 too – by our conventions. The new COBOL 2002 Standard does not discuss Areas A and B very explicitly. But the likelihood of your running into older COBOL programs requiring maintenance is very high. So, we will ‘modestly’ refer to these areas.

6 Let’s take a look: Sample from my web page:

7 IDENTIFICATION DIVISION. PROGRAM-ID. GRADE-TABLES. AUTHOR. author's name omitted. DATE-WRITTEN. 04/17/06 DATE-COMPILED. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT STUDENT-REC ASSIGN TO "C:\COP2120\P6\MumboJumbo\2120P5FL.TXT" ORGANIZATION IS LINE SEQUENTIAL. SELECT REG-PRINT-REC ASSIGN TO "C:\COP2120\P6\MumboJumbo\REG-REPORT.TXT" ORGANIZATION IS LINE SEQUENTIAL. SELECT SPEC-PRINT-REC ASSIGN TO "C:\COP2120\P6\MumboJumbo\SPEC-REPORT.TXT" ORGANIZATION IS LINE SEQUENTIAL.

8

9 Divisions and Sections and Paragraphs Divisions: identification, environment, data, and procedure Ordered. Must appear in order (Environment Division does not ‘have’ to appear, but…) Most are divided into Sections Many Sections are divided into paragraphs. All division, section, and paragraph entries must end with a period. Division and section entries must reside on a line by themselves. Example: Environment Division. Configuration section. Source-computer. PC. Object-computer. PC. Special-names.. Insofar as statements and sentences, these may appear on lines by themselves and with other entries. Example: move spaces to print-rec. add 1 to result. /* Do one statement per line – convention */

10 Coding the Identification Division Small, simplest division of a COBOL program. Is required to identify your program to system. Contents does not affect program execution Identification division: no sections, only paragraphs. Program-id is the only required paragraph.. All A-margin (A area) entries.

11 Syntax of Identification Division Identification Division. Program-id. Program-name. [Author. [Comment-entry]...] [Installation. [Comment-entry]...] [Date-written. [Comment-entry]...] [Date-compiled. [Comment-entry]...] [Security. [Comment-entry]...] Comments : Upper case: COBOL reserved words; special meaning Lower case: programmer-defined Underlined: required entries Punctuation: if specified, it is required. Brackets: option entry Braces: (not shown above): must select the entity or one of the items enclosed in the braces. Later Dots or ellipses (...) means repeated occurrences of preceding items. Called: BNF - Backus Naur Form (Backus normal form) A metalanguage  Discuss...

12 Environment Division Machine-dependent division of a COBOL program Entries are dependent upon the hardware associated. Two sections: Configuration section. (no longer required) Configuration section supplies information on the computer system (source computer and object computer paragraphs) and a few other items. Input-output section. Input-output section names files and associates them with devices. Typically, this is the division that may be changed from computer system to computer system. Older view of COBOL programs might include: Environment division. Configuration section. Source-computer. IBM-370. Object-computer. IBM-370. Note: if entries for source and object computer are used, characters must be contiguous (no embedded spaces) and must be followed with a period.

13 Environment Division Input-Output Section. Name the devices used in the program and Associate a filename with these devices. (In the file-control paragraph) Most of these entries are machine and computing system dependent, while only one part is programmer-defined. File-control paragraph consists of select statements: One select statement per file. Most computer applications have at least one input and one output file - but others may have several of each! Syntax: Select input-transaction-file Assign to “C:\cop2120\p2\BobRoggio\indata.txt” Organization is line sequential. Select master-employee-file Assign to “C:\cop2120\p2\masterfile.dat” Organization is line sequential. Select report-file Assign to “C:\cop2120\p2\output.txt”. Discuss: logical (internal) file names vs external file names. (If extension is.txt, may open with Notepad..dat should be accessed via WordPad)

14 Rules for the Select Statements Rules. use two or three lines for select statements. The file-name-1, like all programmer-defined names, must conform with: 1-30 characters, Letters, digits, hyphens only; No embedded spaces At least one alphabetic character Cannot use any COBOL reserved words (words that have special meaning to the COBOL compiler) (Names should be meaningful and connote proper representation. E.G., Employee-file not "infile" - although i may use these as examples) Implementor names or device specifications Varies widely from manufacturer to manufacturer. Have shown formats to be used using NetExpress.

15 More on Select Statements IBM mainframes use different forms: Examples: Select emp-file assign to ut-s-infile. Select junk-file assign to da-i-myfile. Recognize that this is a standard part of a COBOL program that very frequently is changed when you are moving your COBOL program from one machine to another - particularly between machines manufactured by different vendors!! You can count on this. Whenever you move a program, you will need to find out the new system's select statement formats with regard to the implementation names. Device classes may be ‘ur’ ‘ut’ or ‘da’ (Unit record, utility, or direct access) ur used for: readers, printers, punches, and terminals; ut used for tapes and disk files accessed sequentially; and da used for direct access disk files.) S ==> sequential files; I ==> indexed sequential file; R ==> relative or random files; D ==> direct access;

16 Coding Conventions (Standards) Coding guidelines: see standards!!! See my web page. These standards will be rigidly enforced. Don't use page eject on program listings handed in to me. Do have a single statement per line. (Several statements require two lines. So far: The Select statement) Have all division, section, and paragraph names by themselves on a line. (Division and section entries require their own line. Syntactically, paragraph names are permitted on a line with other code. But don't do this. All paragraph entries on their own line. Use comments liberally! (See standards...) Use meaningful file and data field names such as employee-file or payroll-file

17 Know these things: Divisions SectionsParagraphs (Know this hierarchy) Identification Division. Program-id. (Required). Author. Installation. Date-written. Date-compiled. Security. Environment Division. Configuration Section.(optional) Source-computer. Object-computer. Special-names. Input-output Section. File-control. Select statements…. Data Division. Coming….. File Section. Working-Storage Section. Procedure Division. (procedure division has user-defined sections and paragraph names.)