Structured COBOL Programming, Stern & Stern, 9th Edition CHAPTER 2 Cobol Language Fundamentals.

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)
 2005 Pearson Education, Inc. All rights reserved Introduction.
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)
COBOL for the 21 st Century Stern, Stern, Ley Chapter 1 INTRODUCTION TO STRUCTURED PROGRAM DESIGN IN COBOL.
Introduction to C Programming
COBOL COmmon Business Oriented Language  Work began in 1959 and has never stopped.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
COBOL for the 21st Century
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
Chapter 8 Printing 1. In COBOL you send data to the printer by writing data to a file. In COBOL, the printer is defined as a file, and it is opened, closed,
CS102 Introduction to Computer Programming
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
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.
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.
 2008 Pearson Education, Inc. All rights reserved Introduction to XHTML.
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.
COBOL Cobol is one of the most robust language in the software field, so far Cobol turned 50, in 2009 Cobol has stood the test of time Common Business.
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.
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.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Indexed and Relative File Processing
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 IDENTIFICATION and ENVIRONMENT DIVISIONS. 2 Objectives Basic Structure of COBOL Programs General Coding and Formatting Rules Identification and the.
INPUT / OUTPUT STATEMENTS
Structured Programming
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
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.
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.
Introducing Java Chapter 3 Review. Why Program in Java? Java, is an object-oriented programming language. OOP languages evolved out of the need to better.
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.
Chapter 1: Introduction to Computers and Programming.
Structured Programming
Designing and Debugging Batch and Interactive COBOL Programs
Chapter 3 The DATA DIVISION.
An Introduction to Structured Program Design in COBOL
Structured COBOL Programming
CHAPTER 17 The Report Writer Module
Computer Programming-1 CSC 111
Presentation transcript:

Structured COBOL Programming, Stern & Stern, 9th Edition CHAPTER 2 Cobol Language Fundamentals

BASIC STRUCTURE OF A COBOL PROGRAM

Structured COBOL Programming, Stern & Stern, 9th Edition CODING RULES A COBOL statement is subdivided into 72 positions or columns. Column 7 of a COBOL program has three primary purposes: 1. By coding an * (asterisk) in column 7, an entire line can be designated as a comment. 2. It can be used to force the printing of subsequent instructions on the next page of the source listing. 3. It can be used for the continuation of nonnumeric literals.

Structured COBOL Programming, Stern & Stern, 9th Edition DEBUGGING TIP Use uppercase letters for instructions; – use lowercase letters for comments. Page-Eject with a Slash (/) in Column 7 can also be used to skip to the next page when the source listing is being printed.

Structured COBOL Programming, Stern & Stern, 9th Edition CODING RULES: Areas A and B Positions of a standard COBOL program contain program statements: –Column 8 is labeled the A area –Column 12 is labeled the B area Entries in Area A, may begin in position 8, 9, 10, or 11. –Most often, Area A entries begin in position 8. If an entry is to be coded in Area B, it may begin anywhere after position 11.

Structured COBOL Programming, Stern & Stern, 9th Edition TYPES OF COBOL ENTRIES Divisions, sections, and paragraphs begin in Area A. Examples include: DIVISIONS IDENTIFICATION DIVISION. ENVIRONMENT DIVISION. DATA DIVISION. PROCEDURE DIVISION. SECTIONS FILE SECTION. WORKING-STORAGE SECTION.

Structured COBOL Programming, Stern & Stern, 9th Edition TYPES OF COBOL ENTRIES Divisions, sections, and paragraphs begin in Area A. Examples include: PARAGRAPHS PROGRAM-ID. 0-MAIN-MODULE. 1-BUILD-DETAIL-LINE. Statements and sentences begin in Area B; for example: SELECT PAYROLL ASSIGN TO DISK. ADD AMT-IN TO TOTAL.

Structured COBOL Programming, Stern & Stern, 9th Edition TYPES OF COBOL ENTRIES MARGIN RULES 1. Division, section, and paragraph-names begin in Area A. 2. All other statements, clauses, and sentences begin in Area B.

Structured COBOL Programming, Stern & Stern, 9th Edition CODING REQUIREMENTS OF THE IDENTIFICATION DIVISION

Structured COBOL Programming, Stern & Stern, 9th Edition Paragraphs in the 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]...]

Structured COBOL Programming, Stern & Stern, 9th Edition Rules for Interpreting Instruction Formats 1. Uppercase words are COBOL reserved words 2. Underlined words are required. 3. Lowercase words represent user- defined entries. 4. Braces { } denote that one of the enclosed items is required.

Structured COBOL Programming, Stern & Stern, 9th Edition Rules for Interpreting Instruction Formats 5. Brackets [ ] mean the clause or paragraph is optional. 6. If punctuation is specified in the format, it is required. 7. Dots … or ellipses ( … ) means additional entries of the same type may be optionally added.

Structured COBOL Programming, Stern & Stern, 9th Edition COBOL CHANGES All paragraphs AUTHOR through SECURITY have been deleted from the COBOL standard since they can be easily replaced with comments.

QUESTIONS?

Structured COBOL Programming, Stern & Stern, 9th Edition SELF-TEST 1. If an entry must begin in Area A, it may begin in position _____ ; if an entry must begin in Area B, it may begin in position _____. Solution: 8, 9, 10, or 11; 12, 13, 14, and so on

Structured COBOL Programming, Stern & Stern, 9th Edition SELF-TEST 2. The four divisions of a COBOL program must appear in order as _____ ; _____ ; _____ ; and, _____. Solution: IDENTIFICATION; ENVIRONMENT; DATA; PROCEDURE

Structured COBOL Programming, Stern & Stern, 9th Edition SELF-TEST 3. What entries must be coded beginning in Area A? Solution: Division, section, and paragraph-names

Structured COBOL Programming, Stern & Stern, 9th Edition SELF-TEST 4. Most entries such as PROCEDURE DIVISION instructions are coded in Area _____. Solution: B

Structured COBOL Programming, Stern & Stern, 9th Edition SELF-TEST 5. _____ and _____ must each appear on a separate line. All other entries may have several statements on the same line. Solution: Division names; section names

Structured COBOL Programming, Stern & Stern, 9th Edition SELF-TEST 6. The first two entries of a COBOL program must always be _____ and _____. Solution: IDENTIFICATION DIVISION. PROGRAM-ID. program-name.

Structured COBOL Programming, Stern & Stern, 9th Edition SELF-TEST 7. Each of the preceding entries must be followed by a _____, which, in turn, must be followed by a ____. Solution: period; space or blank

Structured COBOL Programming, Stern & Stern, 9th Edition SELF-TEST 9. Code the IDENTIFICATION DIVISION for a program called EXPENSES for a corporation, Dynamic Data Devices, Inc., written January 18, This program has a security classification and is available to authorized personnel only. It produces a weekly listing by department of all operating expenses.

Structured COBOL Programming, Stern & Stern, 9th Edition SELF-TEST 9. Suggested solution: IDENTIFICATION DIVISION. PROGRAM-ID. EXPENSES. *AUTHOR. N. B. STERN. *INSTALLATION. DYNAMIC DATA DEVICES, INC. *DATE-WRITTEN. 1/18/2007. *DATE-COMPILED. 1/18/2007. *SECURITY. AUTHORIZED PERSONNEL ONLY.

Structured COBOL Programming, Stern & Stern, 9th Edition THE SECTIONS OF THE ENVIRONMENT DIVISION The ENVIRONMENT DIVISION is the only machine-dependent division of a COBOL program. Entries in this division will depend upon: –(1) the computer system and –(2) the specific devices or hardware used in the program.* * Interactive programs that use keyed data as input and display screen output will not need this division.

Structured COBOL Programming, Stern & Stern, 9th Edition THE CONFIGURATION SECTION –Supplies information about the computer on which the COBOL program will be compiled and executed. SOURCE-COMPUTER: –The computer that will be used for compiling the program. OBJECT-COMPUTER: - The computer that will be used for executing or running the program. *SOURCE- COMPUTER and OBJECT-COMPUTER are coded primarily as documentation entries.

Structured COBOL Programming, Stern & Stern, 9th Edition The CONFIGURATION SECTION All section names, like division names, are coded in Area A. The CONFIGURATION SECTION, if coded, will follow the ENVIRONMENT DIVISION entry in Area A. SOURCE-COMPUTER and OBJECT- COMPUTER, as paragraph-names, would also be coded in Area A.

Structured COBOL Programming, Stern & Stern, 9th Edition CONFIGURATION SECTION EXAMPLE ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. IBM iSeries. OBJECT-COMPUTER. IBM iSeries.

Structured COBOL Programming, Stern & Stern, 9th Edition INPUT-OUTPUT SECTION The INPUT-OUTPUT SECTION optionally follows the CONFIGURATION SECTION – It supplies information concerning the input and output devices used in the program by means of a FILE-CONTROL paragraph. In the FILE-CONTROL paragraph, a file- name is designated and assigned to a device for each file used in the program.

Structured COBOL Programming, Stern & Stern, 9th Edition INPUT-OUTPUT SECTION The FILE-CONTROL paragraph consists of SELECT statements –each is coded in Area B followed by a period. A SELECT statement – defines a file-name. – assigns a device name to that file*. A file is the major collection of data for a given application.

Structured COBOL Programming, Stern & Stern, 9th Edition INPUT-OUTPUT SECTION Batch processing applications have an input file and an output file. Interactive processing allows input using a keyboard; – therefore, it is not necessary to establish an input file.

Structured COBOL Programming, Stern & Stern, 9th Edition INPUT-OUTPUT SECTION If the output is printed or saved on disk, an output file must exist in the ENVIRONMENT DIVISION. If the output is displayed on a screen, then no file declaration is necessary in the ENVIRONMENT DIVISION. - When this is the case, the ENVIRONMENT DIVISION may be entirely omitted.

ASSIGNING FILES TO DEVICES IN THE ENVIRONMENT DIVISION

Structured COBOL Programming, Stern & Stern, 9th Edition OVERALL FORMAT The instruction format for the SELECT statement follows: SELECT file-name-1 ASSIGN TO implementor-name-1 [ORGANIZATION IS LINE SEQUENTIAL] –The implementor-name is a machine- dependent device specification that is typically provided by the computer center.

Structured COBOL Programming, Stern & Stern, 9th Edition OVERALL FORMAT REVIEW OF INSTRUCTION FORMAT RULES 1. Uppercase words are reserved words; lowercase words are user-defined. 2. Underlined words are required in the statement. 3. Two lines are used for a SELECT statement – the second line is indented for “ readability”

Structured COBOL Programming, Stern & Stern, 9th Edition OVERALL FORMAT File-Name Rules 1. The file-name assigned to each device must conform to the rules for forming user-defined words. 2. A user-defined word is a word chosen by the programmer to represent some element in a program such as a file-name:

Structured COBOL Programming, Stern & Stern, 9th Edition OVERALL FORMAT Rules for Forming User-Defined Words (Such as File-Names) 1. 1 to 30 characters. 2. Letters, digits, and hyphens (-) only. 3. No embedded blanks –It is best to use hyphens to separate words (e.g., EMPLOYEE-NAME) 4. At least one alphabetic character.

Structured COBOL Programming, Stern & Stern, 9th Edition OVERALL FORMAT 5. May not begin or end with a hyphen. 6. No COBOL reserved words such as DATA, DIVISION, etc. A full list of reserved words appears in Appendix A and in the COBOL Syntax Reference Guide.

Structured COBOL Programming, Stern & Stern, 9th Edition THE NET If you do not have a COBOL Syntax Reference Guide, it can be downloaded from:

Structured COBOL Programming, Stern & Stern, 9th Edition OVERALL FORMAT A SELECT statement must be specified for each file in the program,. If a program requires a disk file as input and produces a printed report as an output file, two SELECT statements will be specified. –one file-name will be assigned to the disk file –the other to the print file.

Structured COBOL Programming, Stern & Stern, 9th Edition DEBUGGING TIP File names assigned by the programmer should be meaningful. Examples: SALES-IN SALES-REPORT-OUT

Structured COBOL Programming, Stern & Stern, 9th Edition OVERALL FORMAT Implementor-Names or Device Specifications Most systems enable the programmer to access frequently used devices by special device names.

Structured COBOL Programming, Stern & Stern, 9th Edition OVERALL FORMAT Implementor-Names or Device Specifications The following are common shorthand device specifications that you will use on our iSeries system: PrinterPRINTER followed by a printer file object name Disk DISK followed by a file or database object name

Structured COBOL Programming, Stern & Stern, 9th Edition SELECT Statements for PCs 1. Device Specification on PCs (a) The drive on which the disk file appears followed by a colon (e.g., C:, D:, etc.). If your file is in a subdirectory, you must specify that as well (e.g., C:\COBOL).

Structured COBOL Programming, Stern & Stern, 9th Edition SELECT Statements for PCs (b) The file-name for that disk file, where the rules for forming file- names are dependent on the operating system. –The device name for these PC versions of COBOL is usually enclosed in quotes: SELECT EMPLOYEE-FILE ASSIGN TO 'C:EMPFILE'. SELECT INVENTORY-FILE ASSIGN TO 'C:\INVENTORY\INVFILE.DAT'.

Structured COBOL Programming, Stern & Stern, 9th Edition SELECT Statements for iSeries 1. Device Specification on the iSeries (a) Refer to the file object name. i.e., assume there is physical file named ROSTER that you want the program to access … You will code SELECT ROSTER-FILE-IN ASSIGN TO DISK-ROSTER.

Structured COBOL Programming, Stern & Stern, 9th Edition CHAPTER SLIDES END HERE CHAPTER SUMMARY COMES NEXT

Structured COBOL Programming, Stern & Stern, 9th Edition CHAPTER SUMMARY I. The IDENTIFICATION DIVISION A. The IDENTIFICATION DIVISION and its paragraphs are used for documentation and do not affect the execution of the program. B. The first two items to be coded in a program are: IDENTIFICATION DIVISION. PROGRAM-ID. program-name. C. A program name that is up to eight characters, letters and digits only, is acceptable on all computers.

Structured COBOL Programming, Stern & Stern, 9th Edition CHAPTER SUMMARY E. Comments can be included in the IDENTIFICATION DIVISION, as well as all other divisions, by coding an * in position 7. –This makes the entire line a comment. –We encourage you to use comments throughout your programs for documentation. F. A slash (/) in column 7 will cause the subsequent lines to be printed on the next page of the source listing.

Structured COBOL Programming, Stern & Stern, 9th Edition CHAPTER SUMMARY II. The ENVIRONMENT DIVISION A. The format for the ENVIRONMENT DIVISION is: ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. computer-name OBJECT-COMPUTER. computer-name INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT file-name-1 ASSIGN TO implementor-name-1

Structured COBOL Programming, Stern & Stern, 9th Edition CHAPTER SUMMARY II. The ENVIRONMENT DIVISION Fully interactive programs that use keyed data as input and screen displays as output are not required to have an ENVIRONMENT DIVISION.

Structured COBOL Programming, Stern & Stern, 9th Edition CHAPTER SUMMARY B. The CONFIGURATION SECTION is usually optional and we recommend you omit it. It supplies documentary information on the computer(s) being used. C. The INPUT-OUTPUT SECTION is also optional but must be included if files are assigned to devices in a program. We will always include the INPUT- OUTPUT SECTION for batch processing.

Structured COBOL Programming, Stern & Stern, 9th Edition CHAPTER SUMMARY D. The ENVIRONMENT DIVISION is the only division of a COBOL program that may vary depending on the computer used. –Obtain the exact device specifications or disk file-name rules from your computer center or your instructor.

Structured COBOL Programming, Stern & Stern, 9th Edition THE NET If you do not have a COBOL Syntax Reference Guide, it can be downloaded from: