Programming in COBOL.

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

DT266/2 COBOL Basics – Declaring Data Basic Operations.
C Language.
2-1 Chapter 2.  Coding Requirements of IDENTIFICATION DIVISION  Sections of ENVIRONMENT DIVISION  Assigning Files to Devices in ENVIRONMENT DIVISION.
Chapter 1: Introduction
The IDENTIFICATION and ENVIRONMENT DIVISIONS Chapter 2.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
Modules, Hierarchy Charts, and Documentation
COBOL for the 21 st Century Stern, Stern, Ley Chapter 1 INTRODUCTION TO STRUCTURED PROGRAM DESIGN IN COBOL.
COBOL COmmon Business Oriented Language  Work began in 1959 and has never stopped.
Computer Science 101 Introduction to Programming.
Structured COBOL Programming, Stern & Stern, 9th edition
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)
Chapter To familiarize you with  Why COBOL is a popular business-oriented language.  Programming practices and techniques  History of COBOL.
Lesson 1: Introduction to ABAP OBJECTS Todd A. Boyle, Ph.D. St. Francis Xavier University.
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.
Computer Science 101 Introduction to Programming.
Chapter 5 Using Data and COBOL Operators. Initializing Variables When you define a variable in WORKING- STORAGE, you also can assign it an initial value.
Implementation of a Stored Program Computer ITCS 3181 Logic and Computer Systems 2014 B. Wilkinson Slides2.ppt Modification date: Oct 16,
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
© 2012 Pearson Education, Inc. All rights reserved. 1-1 Why Java? Needed program portability – Program written in a language that would run on various.
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.
COBOL Basics 2. H E N N E S S Y R M L M F Group Items/Records StudentDetails WORKING-STORAGE SECTION. 01StudentDetailsPIC X(26).
CPSC3111/CISM3111 COBOL Structured COBOL Programming Text: murach’s structured COBOL Authors: Murach, Prince, Menendez.
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.
Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect.
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.
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.
Any Questions? Week 1 - 2nd Lecture Intro to COBOL Programming Defining Files and Processing Data.
© 2012 Pearson Education, Inc. All rights reserved types of Java programs Application – Stand-alone program (run without a web browser) – Relaxed.
CISC105 – General Computer Science Class 2 – 6/7/2006.
Analysis of SAMPLE1.CBL Please check speaker notes for additional information!
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.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
UMBC CMSC 104 – Section 01, Fall 2016
3.1 Fundamentals of algorithms
Concepts of Object Oriented Programming
Submitting Instructions on web site CS 1024 students Read guide
BASIC ELEMENTS OF A COMPUTER PROGRAM
Structured Programming
Programming in COBOL.
Variables, Printing and if-statements
IPC144 Introduction to Programming Using C Week 2 – Lesson 1
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Designing and Debugging Batch and Interactive COBOL Programs
Any Questions?.
2.1 Parts of a C++ Program.
Chapter 3 The DATA DIVISION.
Number and String Operations
An Introduction to Structured Program Design in COBOL
Structured COBOL Programming
Chapter 14 Sorting and Merging.
Programming in COBOL-85 For IBM Mainframe System 390
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
CHAPTER 17 The Report Writer Module
Chapter 2: Introduction to C++.
Using screens and adding two numbers - addda.cbl
Introducing JavaScript
Presentation transcript:

Programming in COBOL

COBOL Origins Developed in 1959-1960; latest standard was released in 2002 Heavy investment from the government and accounting industry, with significant legacy code Created to be the ultimate “portable” language for data processing Academics were not interested in business applications, so designed from the ground up for businessmen

COBOL Today It’s still around! A 2013 Gartner Business Computing report states that 200 times more transactions are processed using COBOL every day than there are google or youtube searches made Still runs (somewhere) in more than 70% of the world’s business You interact with a COBOL based business application an average of at least 7 times per day Design-wise, COBOL applications tend to be huge (millions of lines of code), which may be why they often stick around

COBOL Features Simple, English-like syntax: Weakly typed Rather than y=x; say Move x to y Weakly typed No pointers, user defined types, or user defined functions (at least initially, although some have been retrofitted) Data types are very “structure-like”: can have numeric, alphanumeric (strings), and alphabetic base types, and records formed from these types Hierarchical in structure: almost like an essay, each program has 4 main divisions with subordinate elements in each Some compilers require all 4 to be present, but some only require two

COBOL Elements

The Divisions Part 1: Identification division (required) Supplies information about the program to the programmer and compiler Part 2: Environment division Used to describe the environment in which program should run Part 3: Data division Provides description of the data items the program will process Part 4: Procedure division (required) Contains code used to manipulate the data

Basic format Each line is 80 characters long (a “coding sheet”): Lines 1-6 are for line numbers Line 7 is an indicator: * means comment, - means continuation, and / indicates form feed Lines 8-11, or Area A: All divisions, sections, paragraphs, etc., begin here Lines 12-72, or Area B: All COBOL statements Lines 73-80: Identification area (as needed by programmer)

Sample programs: Hello world

Sample programs: Hello world

Identification Division Mandatory, since it is how the program is identified PROGRAM-ID is the only mandatory part Also often contains AUTHOR, DATE-WRITTEN, and comments to describe content

Environment Division Used to specify input and output files to the program 2 sections: Configuration: information about system on which program is written and executed Input-Output: information about the files to be used

Data Division Defines the variables. 4 sections: File section: define record structure Working-storage section: declare temporary variables and file structures Local-storage section: Similar to above, but variables allocated and initialized with every program execution Linkage section: describes data names received from external program

More on data division: names Data Names: defined here and used in the procedure division (next) for actual commands Some strict rules about what is allowed:

More on data division: level number Level number is used to specify the level of data in a record – differentiates between elementary items and group items Elementary items can’t be divided further Group items consist of one or more elementary item(s)

More on data division: level number Level number is used to specify the level of data in a record – differentiates between elementary items and group items Elementary items can’t be divided further Group items consist of one or more elementary item(s)

More on data division: level number Level number is used to specify the level of data in a record – differentiates between elementary items and group items Elementary items can’t be divided further Group items consist of one or more elementary item(s)

More on data division: pic clauses Picture clauses can be used to define the following items: Data types: can be numeric, alphabetic, or alphanumeric Sign: + or – (for numeric data) Decimal point position (for numeric data), so not included in the data Length: defines number of bytes used by data item So in the previous example: 9 means numeric data, A means alphabetic, X means alphanumeric V is the implicit decimal, S is sign, P is assumed decimal

More on data division: pic clauses

More on data division: value clauses These are optional clauses to initialize data items

Procedure Division Describes the logic of the program Consists of executable statements using variables defined in data division Paragraph and section names here are user defined There must be at least one statement, and last is usually STOP RUN or EXIT PROGRAM

Actions in the procedure division ACCEPT verb gets data from the OS or the user DISPLAY verb prints out INITIALIZE is the verb used to initialize values Puts 0’s or spaces, depending on base type REPLACING term can be used to initialize to the given replacing value

Actions in the procedure division

Actions in the procedure division The MOVE verb copies source data to a specified destination Works on both elementary and group data items For group, use MOVE CORR MOVE(x:l) copies starting at x and for length l If destination is shorter, will add zeroes or spaces to fill out The ADD verb adds (not much to say) SUBTRACT subtracts, but can be used in fun ways

Actions in the procedure division COMPUTE lets you do more arithmetic expressions: COMPUTE VAR = (OTHERVAR1 * OTHERVAR2) – OTHERVAR3 REDEFINES is used to define storage with a different data description RENAMES gives a different name to an existing data item USAGE specifies the OS in which the format date is stored

COBOL control structures

COBOL features: Report writer is a declarative process that creates reports (from the data division) Programmer just specifies the report layout and the data required to produce it No formatting, page breaks, etc, to worry about

COBOL criticisms Criticisms: Not a very structured paradigm Dijkstra: "The use of COBOL cripples the mind; its teaching should, therefore, be regarded as a criminal offense.” GOTOs were a big part of COBOL, leading to “spaghetti code” Have now been replaced with PERFORMs, which promote more modular programming Not very modular: hard to restrict data access, and no way to pass parameters Newer version have added some of these things Intended to be portable, but as of 2001, over 300 dialects Very verbose – over 300 reserved keywords

COBOL on linux If you’d like to play – download GNU COBOL compiler: See here: https://medium.com/@yvanscher/7-cobol- examples-with-explanations-ae1784b4d576 Or more examples: http://www.csis.ul.ie/cobol/examples/default.htm

COBOL takeaway Keep in mind, I was told that this language was “dead” over 20 years ago, and I’ve found articles from the 70s that say the same thing But: Businesses reuse COBOL applications that were written decades ago on new platforms like .NET or JVM. The language itself is portable with data types and structures which enable developers to write applications that can be ported to new platforms with minimal or no change. COBOL has been able to adapt to change: each new enterprise platform which emerges has had COBOL applications deployed there.