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;

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.
Java An introduction. Example 1 public class Example1 { public static void main (String [] args) { System.out.println (“This is the first example”); int.
Data types and variables
Chapter 2 Data Types, Declarations, and Displays
Chapter 2: Introduction to C++.
Input/Output  Input/Output operations are performed using input/output functions  Common input/output functions are provided as part of C’s standard.
Chapter 2 Data Types, Declarations, and Displays.
Objectives You should be able to describe: Data Types
Programming in COBOL-85 For IBM Mainframe System 390
A Variable is symbolic name that can be given different values. Variables are stored in particular places in the computer ‘s memory. When a variable is.
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.
Variables and Data Types
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.
C Tokens Identifiers Keywords Constants Operators Special symbols.
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.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
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.
Module 4 Constants Copy Statement Perform Verb Part 1.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
CS CS Computing for Business Instructor:David Tucker GTA:Batul Mirza.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
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).
Module 2 Defining Data Revised Defining Data All definitions of data for COBOL takes place in the DATA DIVISION. All data defined are visible to.
Lecture #5 Introduction to C++
Chapter 2. C++ Program Structure C++ program is a collection of subprograms Subprograms in C++ are called FUNCTIONS Each function performs a specific.
Knowledge Base C++ #include using std namespace; int main(){} return 0 ; cout
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
Course Title: Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
BASICS CONCEPTS OF ‘C’.  C Character Set C Character Set  Tokens in C Tokens in C  Constants Constants  Variables Variables  Global Variables Global.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
1 IDENTIFICATION and ENVIRONMENT DIVISIONS. 2 Objectives Basic Structure of COBOL Programs General Coding and Formatting Rules Identification and the.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
Structured Programming
CHAPTER # 2 Part 2 PROGRAMS AND DATA 1 st semster King Saud University College of Applied studies and Community Service CSC1101 By: Asma Alosaimi.
CONSTANTS Constants are also known as literals in C. Constants are quantities whose values do not change during program execution. There are two types.
Structured COBOL Programming, Stern & Stern, 9th Edition CHAPTER 2 Cobol Language Fundamentals.
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.
Lecture 21 ENVIRONMENT DIVISION  defines files external to the program and devices.  contains two sections: 1.CONFIGURATION SECTION.  identifies computers.
Variables, Input, and Output. Challenge: ● Ask the user his or her name, and repeat that name to the user ● Pause video and try.
Ajmer Singh PGT(IP) Programming Fundamentals. Ajmer Singh PGT(IP) Java Character Set Character set is a set of valid characters that a language can recognize.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
The PERFORM. The PERFORM Verb  Iteration is an important programming construct. We use iteration when we need to repeat the same instructions over and.
Week 2/3 - 2nd Lecture Intro to COBOL Programming Defining Files and Processing Data.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
Introduction to Sequential Files. COBOL's forte  COBOL is generally used in situations where the volume of data to be processed is large.  These systems.
Chapter # 2 Part 2 Programs And data
Chapter 2: Introduction to C++
© 2016 Pearson Education, Ltd. All rights reserved.
Structured Programming
ITEC113 Algorithms and Programming Techniques
Programming in COBOL.
Input/Output Input/Output operations are performed using input/output functions Common input/output functions are provided as part of C’s standard input/output.
IDENTIFIERS CSC 111.
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
2.1 Parts of a C++ Program.
Chapter 3 The DATA DIVISION.
Chapter # 2 Part 2 Programs And data
Chapter 2: Introduction to C++.
7 – Variables, Input and Output
Presentation transcript:

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; Area A and Area B  When a COBOL compiler recognizes these two areas, all division, section, paragraph names, FD entries and 01 level numbers must start in Area A. All other sentences must start in Area B.  Area A is four characters wide and is followed by Area B.  In Microfocus COBOL the compiler directive $ SET SOURCEFORMAT"FREE" frees us from all formatting restrictions.

COBOL coding rules $ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. ProgramFragment. * This is a comment. It starts * with an asterisk in column 1 $ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. ProgramFragment. * This is a comment. It starts * with an asterisk in column 1  Almost all COBOL compilers treat a line of COBOL code as if it contained two distinct areas. These are known as; Area A and Area B  When a COBOL compiler recognizes these two areas, all division, section, paragraph names, FD entries and 01 level numbers must start in Area A. All other sentences must start in Area B.  Area A is four characters wide and is followed by Area B.  In Microfocus COBOL the compiler directive $ SET SOURCEFORMAT"FREE" frees us from all formatting restrictions.

Name Construction.  All user defined names, such as data names, paragraph names, section names and mnemonic names, must adhere to the following rules; l They must contain at least one character and not more than 30 characters. l They must contain at least one alphabetic character and they must not begin or end with a hyphen. l They must be contructed from the characters A to Z, the number 0 to 9 and the hyphen. e.g. TotalPay, Gross-Pay, PrintReportHeadings, Customer10-Rec  All data-names should describe the data they contain.  All paragraph and section names should describe the function of the paragraph or section.

Describing DATA.  Variables.  Literals.  Figurative Constants. Unlike other programming languages, COBOL does not support user defined constants. There are basically three kinds of data used in COBOL programs;

Data-Names / Variables  A variable is a named location in memory into which a program can put data and from which it can retrieve data.  A data-name or identifier is the name used to identify the area of memory reserved for the variable.  Variables must be described in terms of their type and size.  Every variable used in a COBOL program must have a description in the DATA DIVISION.

StudentName Using Variables MOVE "JOHN" TO StudentName. DISPLAY "My name is ", StudentName. 01 StudentNamePIC X(6) VALUE SPACES.

StudentName MOVE "JOHN" TO StudentName. DISPLAY "My name is ", StudentName. 01 StudentNamePIC X(6) VALUE SPACES. J O H N Using Variables

StudentName MOVE "JOHN" TO StudentName. DISPLAY "My name is ", StudentName. 01 StudentNamePIC X(6) VALUE SPACES. My name is JOHN Using Variables J O H N

COBOL Data Types  COBOL is not a “typed” language and the distinction between some of the data types available in the language is a little blurred.  For the time being we will focus on just two data types, l numeric l text or string  Data type is important because it determines the operations which are valid on the type.  COBOL is not as rigorous in the application of typing rules as other languages. For example, some COBOL “numeric” data items may, from time to time, have values which are not “numeric”!

Quick Review of “Data Typing”  In “typed” languages simply specifying the type of a data item provides quite a lot of information about it.  The type usually determines the range of values the data item can store. l For instance a CARDINAL item can store values between 0..65,535 and an INTEGER between -32, ,767  From the type of the item the compiler can establish how much memory to set aside for storing its values.  If the type is “REAL” the number of decimal places is allowed to vary dynamically with each calculation but the amount of the memory used to store a real number is fixed.

COBOL data description.  Because COBOL is not typed it employs a different mechanism for describing the characteristics of the data items in the program.  COBOL uses what could be described as a “declaration by example” strategy.  In effect, the programmer provides the system with an example, or template, or PICTURE of what the data item looks like.  From the “picture” the system derives the information necessary to allocate it.

COBOL ‘PICTURE’ Clause symbols  To create the required ‘picture’ the programmer uses a set of symbols.  The following symbols are used frequently in picture clauses; l 9 (the digit nine) is used to indicate the occurrence of a digit at the corresponding position in the picture. l X (the character X) is used to indicate the occurrence of any character from the character set at the corresponding position in the picture l V (the character V) is used to indicate position of the decimal point in a numeric value! It is often referred to as the “assumed decimal point” character. l S (the character S) indicates the presence of a sign and can only appear at the beginning of a picture.

COBOL ‘PICTURE’ Clauses  Some examples l PICTURE 999 a three digit (+ive only) integer l PICTURE S999a three digit (+ive/-ive) integer l PICTURE XXXXa four character text item or string l PICTURE 99V99a +ive ‘real’ in the range 0 to l PICTURE S9V9a +ive/-ive ‘real’ in the range ?  If you wish you can use the abbreviation PIC.  Numeric values can have a maximum of 18 (eighteen) digits (i.e. 9’s).  The limit on string values is usually system-dependent.

Abbreviating recurring symbols  Recurring symbols can be specified using a ‘repeat’ factor inside round brackets l PIC 9(6) is equivalent to PICTURE l PIC 9(6)V99 is equivalent to PIC V99 l PICTURE X(10) is equivalent to PIC XXXXXXXXXX l PIC S9(4)V9(4) is equivalent to PIC S9999V9999 l PIC 9(18) is equivalent to PIC

Declaring DATA in COBOL  In COBOL a variable declaration consists of a line containing the following items;  A level number.  A data-name or identifier.  A PICTURE clause.  We can give a starting value to variables by means of an extension to the picture clause called the value clause. DATA DIVISION. WORKING-STORAGE SECTION. 01 Num1 PIC 999VALUE ZEROS. 01 VatRate PIC V99VALUE StudentName PIC X(10)VALUE SPACES. Num1 VatRate StudentName D ATA

COBOL Literals.  String/Alphanumeric literals are enclosed in quotes and may consists of alphanumeric characters e.g. "Michael Ryan", "-123", "123.45"  Numeric literals may consist of numerals, the decimal point and the plus or minus sign. Numeric literals are not enclosed in quotes. e.g. 123, , -256, +2987

Figurative Constants  COBOL provides its own, special constants called Figurative Constants. SPACE or SPACES SPACE or SPACES =  ZERO or ZEROS or ZEROS ZERO or ZEROS or ZEROS =0 QUOTE or QUOTES QUOTE or QUOTES =" HIGH-VALUE or HIGH-VALUES HIGH-VALUE or HIGH-VALUES =Max Value LOW-VALUE or LOW-VALUES LOW-VALUE or LOW-VALUES =Min Value ALL literal ALL literal =Fill With Literal SPACE or SPACES SPACE or SPACES =  ZERO or ZEROS or ZEROS ZERO or ZEROS or ZEROS =0 QUOTE or QUOTES QUOTE or QUOTES =" HIGH-VALUE or HIGH-VALUES HIGH-VALUE or HIGH-VALUES =Max Value LOW-VALUE or LOW-VALUES LOW-VALUE or LOW-VALUES =Min Value ALL literal ALL literal =Fill With Literal

Figurative Constants - Examples 01 GrossPay PIC 9(5)V99 VALUE MOVE TO GrossPay. 01 GrossPay PIC 9(5)V99 VALUE MOVE TO GrossPay. ZERO ZEROS ZEROES 01 StudentName PIC X(10) VALUE "MIKE". MOVE ALL "-" TO StudentName. 01 StudentName PIC X(10) VALUE "MIKE". MOVE ALL "-" TO StudentName. StudentName M I K E  GrossPay 

Figurative Constants - Examples 01 GrossPay PIC 9(5)V99 VALUE MOVE TO GrossPay. 01 GrossPay PIC 9(5)V99 VALUE MOVE TO GrossPay. ZERO ZEROS ZEROES 01 StudentName PIC X(10) VALUE "MIKE". MOVE ALL "-" TO StudentName. 01 StudentName PIC X(10) VALUE "MIKE". MOVE ALL "-" TO StudentName. StudentName GrossPay 