SlideShare una empresa de Scribd logo
1 de 52
COBOL
(COMMON BUSINESS ORIENTED
LANGUAGE)
By: Manjula Sanjay
Asst. prof, Dept. of MCA
Objective
 COBOL is one of the most widespread commercial applications languages in use
today. The course is aimed at developers to get the basic knowledge of COBOL
program development. This course covers all aspects of Programming with
COBOL.
 The course teaches the design, writing and testing of COBOL programs.
Having studied this subject, the students should be able:
 Develop Structured COBOL Programs
 Understand and Use COBOL Verbs
 Develop COBOL programs using the available verbs
 Develop and Test COBOL print programs
 Develop and Test COBOL programs accessing different types of files
Text Books
 Text Book
 Nancy Stern and Robert A Stern, 11th
edition, Structured
COBOL Programming, John Wiley & Sons, 1998.
 Reference Book
 M.K.Roy and D. Ghosh Dastidar, COBOL Programming,
Tata McGraw Hill, 2001, COBOL—85,2nd
Edition.
Introduction
 Types of computer programs
 Operating system programs
 Application programs / Software
 Types of Processing
 Interactive – A point-of-Sale system
 Batch processing – Payroll System (Large volume of
input at periodic intervals)
 COBOL support both type of processing
 Customized Application Package: Budget, Scheduling etc.
 Machine language programs
 Symbolic programs : translates to machine language by
Program Development Process
 Determine the program specification
 Design the program using program planning tools
 Code the program
 Compile the program
 Test the program
 Document the program
Compile the program
Source program
in symbolic
language
Object program
in machine
language
Translated by
compiler
Test the program
 Debug during compile & test phase
 Compile time errors: Syntax error e.g. ADD | AD
 Misspelled reserved words
 Missing punctuation
 Execution errors: Logic error e.g. ADD instead of
Multiply
 Run-Time error: Occurs if computer cannot execute
the instruction.
E.g.-
 Attempt to divide by zero
 Reading from a file that cannot be found.
Contents
 History of COBOL
 Features & Language Fundamentals
 Program Structure
 Coding Format for COBOL Programs
 Character Set, Words, Data Names, Literals.
Nature of COBOL
 popular Business-oriented language
 Standard language
 English-like language: Standard & business oriented
 Relatively easy to understand- User friendly
 Reference: http://www.ansi.org
History of COBOL
 1959 – United States Department of Defense
 1960 - COBOL initial specifications presented by CODASYL
(COnference on Data SYstems Languages)
 1961 – COBOL 61
 1964 – BASIC COBOL extended to Visual COBOL
 1968 – ANSI (American National Standards Institute) developed
American National Standard (ANS) COBOL
 1974 – ANSI published revised version of (ANS) COBOL
– Business applications needed to manipulate character as
well as numeric data
– String operations added
 1985 – COBOL 85 Standards was introduced with revised
version of COBOL-74.
COBOL
 What does COBOL stand for?
COmmon Business Oriented Language.
 Which are target area of COBOL applications?
Defense, Aircraft, Insurance, Finance, Retail
etc.
(file & data oriented applications involved)
 So we can say that COBOL is basically used for writing
business applications and not for developing system
software
Future of COBOL
 COBOL is likely to remain an important language in the years
ahead
 According to Datapro Information Services Group
about 150 billion lines of COBOL source code in
use
 5 billion new lines added each year
 Cobol is used by 42.7% of application
programmers in medium to large U.S. companies
 $200 million revenues for 2001
Year 2000 Problem (Y2K)
 Year stored as two digits in older programs to save
space
 19 assumed as valid prefix for all years
 95 represented year 1995
 Invalid as prefix for years 2000 and beyond
 00 could mean 1900 or 2000
Year 2000 Problem (Y2K)
Many calculations with dates incorrect starting in 2000
 To find your age if you were born in 1970
Subtract 70 from 95 (95 - 70 = 25)
 Calculation incorrect for year 2000 and beyond
00 - 70 = -70 when age should be 30
Year 2000 Problem (Y2K)
To correct problem
 Billions of lines of code, many written in COBOL
needed to be examined
 Code changed to use four digits for year
 Age, other calculations now correct
1995 - 1970 = 25
2000 - 1970 = 30
2012 – 1988 = 24
Improving Program Design
Two techniques used to develop programs that are easier to
understand, test, debug and modify
 Structured Programming
 Top-Down Programming
Structured Programming
 Eliminates use of GO TO statements
 Allowed skipping to different sections of program without
returning to starting point
 Program logic easier to follow with "GO-TO-less"
programming
Structured Programming
Program divided into paragraphs
 Structured programming follows logical control constructs
that make program easier to read, modify, and debug.
 Main paragraph or module controls logic flow using
PERFORM statements
 Main module "performs" other modules when instructions in
that module required
 Each module can be written and tested independently of
others
Top-Down Programming
 Another technique to make programs easier to understand,
test, debug and modify
 Develop program like term paper
 Develop outline first
 Add details for each of main steps
 Add further refinement for more complex steps
Top-Down Programming
For COBOL program
 Code main modules or routines first
 Code intermediate modules next
 Details deferred to minor modules and coded last
COBOL – Program Structure
Principal portions of a program.
There are 4 divisions –
a) Identification (Required)
b) Environment (Optional)
c) Data (Optional)
d) Procedure (Required)
User defined chunk of code
which consists of one/more
paragraphs.
e.g.
a) U000-CHECK-LOG SECTION.
b) FILE SECTION.
User defined chunk of code
which consists of one/more
sentences.
e.g.
a) P000-PRINT-FINAL-TOTALS.
b) PROGRAM-ID.
A SENTENCE consists of one or
more statements and is
terminated by a full stop.
e.g. a) MOVE .21 TO VAT-RATE
b) COMPUTE VAT-AMOUNT =
PRODUCT-COST * VAT-RATE.
PROGRAM
DIVISIONS
SECTIONS
PARAGRAPHS
SENTENCES
STATEMENTS
A STATEMENT consists of a
COBOL verb and an
operand or operands.
e.g.
SUBTRACT T-TAX FROM GROSS-
PAY GIVING NET-PAY
CHARACTERS
RESERVED WORDS
USER DEFINED WORDS
Example
IDENTIFICATION DIVISION.
PROGRAM-ID. Multiplier.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 Num1 PIC 9 VALUE ZEROS.
01 Num2 PIC 9 VALUE ZEROS.
01 Result PIC 99 VALUE ZEROS.
PROCEDURE DIVISION.
DISPLAY "Enter first number (1 digit) : " .
ACCEPT Num1.
DISPLAY "Enter second number (1 digit) : “.
ACCEPT Num2.
MULTIPLY Num1 BY Num2 GIVING Result.
DISPLAY "Result is = ", Result.
STOP RUN.
1. DIVISIONS
 A DIVISION is the largest unit in the COBOL program and is a
collection of SECTIONs and/or paragraphs. Every COBOL
program is divided into four DIVISIONS.
 IDENTIFICATION DIVISION
 Identifies the program to the computer. It also provide
documentation about the program
 ENVIRONMENT DIVISION
 Define file-names and describe computer equipment used by the
program
 DATA DIVISION
 Describe input and output format used by the program. Also define
constants and work areas necessary for processing the data
 PROCEDURE DIVISION
 Instructions for reading input, processing and creating output
2. SECTIONS
 A SECTION is a collection of related paragraphs.
 The IDENTIFICATION DIVISION doesn’t contain any
SECTIONs, the ENVIRONMENT AND DATA DIVISIONs
have pre-defined SECTIONs that you may or may not
include, depending on the requirement and the
PROCEDURE DIVISION may contain only user defined
SECTIONs.
 A user defined SECTION is indicated by a user-defined word
followed by the reserved word SECTION.
 It is used mainly to divide the executable program into units
that can be loaded and executed independently.
 Thus, a program larger than the memory size can be
accommodated in memory.
3. PARAGRAPHS & 4. SENTENCES
3)
 A paragraph is a collection of sentences that form a
logical unit in a COBOL program.
 It is the basic unit of organisation of a COBOL
program and is referred by a user-defined name in
the program.
4)
 A sentence is a sequence of one or more statements,
ending with a period.
5. STATEMENTS
 A statement is a valid combination of a COBOL verb and its
operands.
 It specifies an action to be taken by the object program.
 The COBOL statements can be broadly classified into two
types -
 Imperative statements
 An imperative statement begins with a verb and
specifies an unconditional action to be taken.
 Conditional statements.
 A conditional statement is one in which the action to be
taken is determined by some condition that is evaluated
when the program is executed.
6. RESERVED WORDS
 A reserved word is a character-string with a predefined
meaning in a COBOL source program.
 There are several types of reserved words in COBOL.
 Keywords:- appear in uppercase.
 Eg ADD, READ etc
 Optional Words:- They improve readability.
 Eg GIVING, AFTER etc
 Figurative constants:- Refer to constant values.
 Eg ZEROES, SPACES etc
7. USER DEFINED WORDS
 They are constructed and used by the application
programmer.
 They are normally used to define paragraph names,
SECTION names, file names, temporary variables,
etc.,
 The following are the rules for forming user-defined
words.
 Length may be up to 30 characters.
 Only letters, digits and hyphen (-) are allowed.
 Embedded blanks are not allowed.
 At least one character must be alphabetic.
 Cannot be COBOL reserved words.
 May not begin or end with hyphen.
8. CHARACTERS
 The most basic and indivisible unit of the COBOL
language is the character.
 The COBOL character set includes 78 characters that can
be classified as letters of the alphabet, digits and special
Characters.
COBOL coding sheet
Column numbers
1 2 3 4 5 6 7 8 9 10 11 12 13 14 . . . . . . . 72 80
Column
numbers
* Area A Area B
I
D
E
N
T
I
F
I
C
A
T
I
O
N
A
R
E
A
-
/
COBOL coding rules
 Each line is considered to be made up of 80 columns.
 Columns 1 to 6 are reserved for sequence numbers.
1 to 3 ---Page Number. 4 to 6 ---Line Number
 Column 7 is an indicator column and has special
meaning to the compiler.
Hyphen ( - ) indicates continuation.
Slash ( / ) indicates comment line , forces page break when
printing source listing.
Asterisk ( * ) indicates comment line, no such page ejection.
 Columns 8 to 11 are called Area A. All COBOL DIVISIONs,
SECTIONs, paragraphs and some special entries must begin in
Area A.
 Columns 12 to 72 are called Area B. All COBOL statements must
begin in Area B.
COBOL coding sheet
Almost all COBOL compilers treat a line of COBOL
code as if it contained two distinct areas. These are -
AREA A
*) Between Column 8 to 11
*) Division, Section, Paragraph
names, FD entries & 01
level entries must start in
Area A
AREA B
*) Between Column 12 to 72
*) All Sentences & Statements
start in Area B
coding rules
 Columns 73 to 80 are identification area. Anything written in
this area , will be ignored by the compiler but will appear in the
source listing.
 Columns 1-6 and 73-80 optional and rarely used today
 Column 7 for continuation, comment, starting new page
 Columns 8-72 for COBOL program statements
Column 7
/ (slash) forces page break when printing source listing
* (asterisk) designates entire line as comment
- (dash) to indicate continuation of nonnumeric literal
Margin Rules
 Columns 8-72 divided into two areas
 Area A - columns 8, 9, 10, 11
 Area B - columns 12-72
 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
 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
COBOL CHARACTER
SET
Overview
Character Meaning
Space
+ Plus sign
- Minus sign or hyphen
* Asterisk
/ Forward slash or solidus
= Equal sign
$ or £ Currency sign
, Comma
; Semicolon
. Decimal point or period
" Quotation mark
( Left parenthesis
) Right parenthesis
> Greater than
< Less than
A-Z (26) Alphabet (uppercase)
a-z Alphabet (lowercase)
0-9 (10) Numeric characters
COBOL Words
 0-9 , A-Z and - Hyphen
 The total no of character must not be greater than 30.
 One of the character must be a letter.
 A word cannot begin with Hyphen.
 A word must not contain a blank or special character except
Hyfen (-)
 A Cobol word can be User defined or reserve word
Valid words Invalid Words
GROSS-PAY -Gross-
OVERTIME-HOURS OVERTIME HOUR
A 1-2-3
B12-4 More than 30 characters
Data names and Identifiers
 Data names are named memory locations.
 Data Names must be described in the DATA DIVISION before
they can be used in the PROCEDURE DIVISION.
 Can be of elementary or group type.
 Can be subscripted for Arrays.
 Are user defined words.
 Ingle data name or a data name qualified, indexed or
subscripted is normally referred to by the general term
identifier.
 Valid data names: A12 sum-natural net-pay
 Invalid: DATA ADD 45 46+2A
Rules for forming User-defined words/Data
names
 Can be at most 30 characters in length.
 At least one alphabetic character.
 Only alphabets, digits and hyphen are allowed.
 Blanks are not allowed.
 May not begin or end with a hyphen.
 Should not be a COBOL reserved word like
ADD,SUBTRACT,MOVE,DISPLAY etc….
Data-Name Guidelines
1. Use meaningful data-names that describe contents of field
2. Use prefixes or suffixes in data-names when appropriate
• -IN and -OUT for fields (Emp-Salary-IN and Emp-Salary-
OUT)
• -FILE and -RECORD for file and record names
• Emp-File or Emp-Record
• Amount-Due-In instead of A1
Identify the valid data-names
• Identify the valid data-names
1. Date-Of-Birth
2. Amount$Out
3. -First-Name
4. 98-6
5. Time out
6. ADD
Literals
 Literals are symbols whose value does not change in a program.
 A data name may have different values at different points of time
whereas a literal means the specific value which remains
unchanged throughout the execution of the program. For this
reason a literal is often called a constant.
Example--- MOVE 0 to sum. (Here 0 is literal)
 There are 3 types of literals namely
(1) Numeric literals.
(2) Non-numeric literals.
(3) Figurative constants.
Rules for Numeric Literals
1. A numeric literal can be formed with the help of digits only.
2. The maximum number of digits allowed in a numeric literal
varies from compiler to compiler. can have a maximum of
18 digits.
3. + or - sign may be included to left of first digit.
4. Decimal point permitted within literal. May not follow last
digit.
Valid numeric literals
23 , +2359.4 , .125 , -68734
Rules for Nonnumeric Literals
• Composed of characters which are enclosed within quotation
marks.
• Generally used for output messages or headings.
• Any character in COBOL character set except quotation mark.
• The maximum number of characters that are allowed is compiler
dependent. ANSI 74: 120 characters.
Valid Nonnumeric Literals
“123 Main St.” “$14.99”
“12,342” “Enter a value from 1 to 10”
Figurative Constants
 These are literals representing values that may be frequently
used by most programs.
 These are given some fixed names and when the compiler
recognizes these names it sets up the corresponding values
in the object program.
 Example--- MOVE ZERO TO sum.
 MOVE SPACES TO REPORT-REC.
 The following is the list of figurative constants and their
meanings.
Figurative constants Meaning
ZERO(S) or ZEROES Represents the value 0, one or
more depending on the context
SPACE(S) Represents one or more spaces
HIGH-VALUE(S) Represents the highest value
LOW-VALUE(S) Represents the lowest value
QUOTE(S) Represents single or double
quotes
ALLALL literalliteral Fill With Literal
Literals – Figurative Constants
Figurative Constants - Examples
01 GrossPay PIC 9(5)V99 VALUE 13.5.
MOVE TO GrossPay.
01 GrossPay PIC 9(5)V99 VALUE 13.5.
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 EM I K E 
GrossPay
0 0 0 1 3 5 0

Figurative Constants - Examples
01 GrossPay PIC 9(5)V99 VALUE 13.5.
MOVE TO GrossPay.
01 GrossPay PIC 9(5)V99 VALUE 13.5.
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
0 0 0 0 0 0 0

Continuation of Lines
 A statement or an entry may be continued to the area B of the
next line as and when necessary.
 A hyphen(-) is used in the indicator field for continuation of
lines.
 Actually, a hyphen in the indicator field means that the first non-
blank character in the area B of the current line is the character
immediately following the last non-blank character of the
previous line.
 Example—In case of non numeric literal
Indicator line Area A Area B
Continued line “Enter the
Continuation Line - “Number”.
 Is Cobol still used ?
 75% of all business data is processed in COBOL.
 There are between 180 billion and 200 billion lines of
COBOL code in use worldwide.
 15% of all new applications (5 billion lines) through 2009 will
be in COBOL.
Thank You

Más contenido relacionado

La actualidad más candente

Mule copy book-tutorial
Mule copy book-tutorialMule copy book-tutorial
Mule copy book-tutorialNagendra Kumar
 
A Research Study of Data Collection and Analysis of Semantics of Programming ...
A Research Study of Data Collection and Analysis of Semantics of Programming ...A Research Study of Data Collection and Analysis of Semantics of Programming ...
A Research Study of Data Collection and Analysis of Semantics of Programming ...IRJET Journal
 
A Checklist for Migrating Big Iron Cobol Applications
A Checklist for Migrating Big Iron Cobol ApplicationsA Checklist for Migrating Big Iron Cobol Applications
A Checklist for Migrating Big Iron Cobol ApplicationsCognizant
 
The Programmer Life Cycle
The Programmer Life CycleThe Programmer Life Cycle
The Programmer Life CycleRussell Ovans
 
Introduction to embedded c
Introduction to embedded cIntroduction to embedded c
Introduction to embedded cGokuldhev mony
 
GENERATING SOFTWARE PRODUCT LINE MODEL BY RESOLVING CODE SMELLS IN THE PRODUC...
GENERATING SOFTWARE PRODUCT LINE MODEL BY RESOLVING CODE SMELLS IN THE PRODUC...GENERATING SOFTWARE PRODUCT LINE MODEL BY RESOLVING CODE SMELLS IN THE PRODUC...
GENERATING SOFTWARE PRODUCT LINE MODEL BY RESOLVING CODE SMELLS IN THE PRODUC...ijseajournal
 
Programming Guidelines
Programming GuidelinesProgramming Guidelines
Programming GuidelinesRamesh Joshi
 
Software programming and development
Software programming and developmentSoftware programming and development
Software programming and developmentAli Raza
 
An introduction to programming
An introduction to programmingAn introduction to programming
An introduction to programmingrprajat007
 

La actualidad más candente (19)

Mule copy book-tutorial
Mule copy book-tutorialMule copy book-tutorial
Mule copy book-tutorial
 
A Research Study of Data Collection and Analysis of Semantics of Programming ...
A Research Study of Data Collection and Analysis of Semantics of Programming ...A Research Study of Data Collection and Analysis of Semantics of Programming ...
A Research Study of Data Collection and Analysis of Semantics of Programming ...
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
A Checklist for Migrating Big Iron Cobol Applications
A Checklist for Migrating Big Iron Cobol ApplicationsA Checklist for Migrating Big Iron Cobol Applications
A Checklist for Migrating Big Iron Cobol Applications
 
Am4201257261
Am4201257261Am4201257261
Am4201257261
 
The Programmer Life Cycle
The Programmer Life CycleThe Programmer Life Cycle
The Programmer Life Cycle
 
Ppt 1
Ppt 1Ppt 1
Ppt 1
 
Abc c program
Abc c programAbc c program
Abc c program
 
Introduction to embedded c
Introduction to embedded cIntroduction to embedded c
Introduction to embedded c
 
Basic Meaning of Computer languages
Basic Meaning of Computer languagesBasic Meaning of Computer languages
Basic Meaning of Computer languages
 
GENERATING SOFTWARE PRODUCT LINE MODEL BY RESOLVING CODE SMELLS IN THE PRODUC...
GENERATING SOFTWARE PRODUCT LINE MODEL BY RESOLVING CODE SMELLS IN THE PRODUC...GENERATING SOFTWARE PRODUCT LINE MODEL BY RESOLVING CODE SMELLS IN THE PRODUC...
GENERATING SOFTWARE PRODUCT LINE MODEL BY RESOLVING CODE SMELLS IN THE PRODUC...
 
Programming Languages
Programming LanguagesProgramming Languages
Programming Languages
 
C languaGE UNIT-1
C languaGE UNIT-1C languaGE UNIT-1
C languaGE UNIT-1
 
Presentation on C programming language
Presentation on C programming languagePresentation on C programming language
Presentation on C programming language
 
Programming Guidelines
Programming GuidelinesProgramming Guidelines
Programming Guidelines
 
Software programming and development
Software programming and developmentSoftware programming and development
Software programming and development
 
An introduction to programming
An introduction to programmingAn introduction to programming
An introduction to programming
 
La5 programming
La5  programmingLa5  programming
La5 programming
 
df
dfdf
df
 

Similar a Chapter 1

Cobol training class-1
Cobol training class-1Cobol training class-1
Cobol training class-1Anil Polsani
 
Skillwise - Cobol Programming Basics
Skillwise - Cobol Programming BasicsSkillwise - Cobol Programming Basics
Skillwise - Cobol Programming BasicsSkillwise Group
 
Converting to the latest COBOL Compiler made simple with the right tools
Converting to the latest COBOL Compiler made simple with the right toolsConverting to the latest COBOL Compiler made simple with the right tools
Converting to the latest COBOL Compiler made simple with the right toolsDevOps for Enterprise Systems
 
Comso c++
Comso c++Comso c++
Comso c++Mi L
 
Cobol programming language
Cobol programming languageCobol programming language
Cobol programming languageBurhan Ahmed
 
CS8251_QB_answers.pdf
CS8251_QB_answers.pdfCS8251_QB_answers.pdf
CS8251_QB_answers.pdfvino108206
 
INTRODUCTION TO C PROGRAMMING MATERIAL.pdf
INTRODUCTION TO C PROGRAMMING MATERIAL.pdfINTRODUCTION TO C PROGRAMMING MATERIAL.pdf
INTRODUCTION TO C PROGRAMMING MATERIAL.pdfSubramanyambharathis
 
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTTC programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTTBatra Centre
 
presentation on the topic: Introduction to the C language
presentation on the topic: Introduction to the C languagepresentation on the topic: Introduction to the C language
presentation on the topic: Introduction to the C languageGautamGupta136
 
IP Lab Manual for Kerala University 3 Year UG Programme
IP Lab Manual for Kerala University 3 Year UG ProgrammeIP Lab Manual for Kerala University 3 Year UG Programme
IP Lab Manual for Kerala University 3 Year UG ProgrammeSAFAD ISMAIL
 

Similar a Chapter 1 (20)

Cobol training class-1
Cobol training class-1Cobol training class-1
Cobol training class-1
 
Cobol
CobolCobol
Cobol
 
Skillwise - Cobol Programming Basics
Skillwise - Cobol Programming BasicsSkillwise - Cobol Programming Basics
Skillwise - Cobol Programming Basics
 
Bca cobol
Bca cobolBca cobol
Bca cobol
 
WEBSITE DEVELOPMENT
WEBSITE DEVELOPMENTWEBSITE DEVELOPMENT
WEBSITE DEVELOPMENT
 
Cobol簡介
Cobol簡介Cobol簡介
Cobol簡介
 
Converting to the latest COBOL Compiler made simple with the right tools
Converting to the latest COBOL Compiler made simple with the right toolsConverting to the latest COBOL Compiler made simple with the right tools
Converting to the latest COBOL Compiler made simple with the right tools
 
Comso c++
Comso c++Comso c++
Comso c++
 
Cobol programming language
Cobol programming languageCobol programming language
Cobol programming language
 
All around cobol
All around cobolAll around cobol
All around cobol
 
CS8251_QB_answers.pdf
CS8251_QB_answers.pdfCS8251_QB_answers.pdf
CS8251_QB_answers.pdf
 
INTRODUCTION TO C PROGRAMMING MATERIAL.pdf
INTRODUCTION TO C PROGRAMMING MATERIAL.pdfINTRODUCTION TO C PROGRAMMING MATERIAL.pdf
INTRODUCTION TO C PROGRAMMING MATERIAL.pdf
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTTC programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
 
presentation on the topic: Introduction to the C language
presentation on the topic: Introduction to the C languagepresentation on the topic: Introduction to the C language
presentation on the topic: Introduction to the C language
 
C programming
C programming C programming
C programming
 
C programming
C programmingC programming
C programming
 
IP Lab Manual for Kerala University 3 Year UG Programme
IP Lab Manual for Kerala University 3 Year UG ProgrammeIP Lab Manual for Kerala University 3 Year UG Programme
IP Lab Manual for Kerala University 3 Year UG Programme
 
Unit-2.pptx
Unit-2.pptxUnit-2.pptx
Unit-2.pptx
 
Debug tool
Debug toolDebug tool
Debug tool
 

Último

4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Presentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxPresentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxRosabel UA
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Projectjordimapav
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationRosabel UA
 

Último (20)

4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Presentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxPresentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptx
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Project
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translation
 

Chapter 1

  • 1. COBOL (COMMON BUSINESS ORIENTED LANGUAGE) By: Manjula Sanjay Asst. prof, Dept. of MCA
  • 2. Objective  COBOL is one of the most widespread commercial applications languages in use today. The course is aimed at developers to get the basic knowledge of COBOL program development. This course covers all aspects of Programming with COBOL.  The course teaches the design, writing and testing of COBOL programs. Having studied this subject, the students should be able:  Develop Structured COBOL Programs  Understand and Use COBOL Verbs  Develop COBOL programs using the available verbs  Develop and Test COBOL print programs  Develop and Test COBOL programs accessing different types of files
  • 3. Text Books  Text Book  Nancy Stern and Robert A Stern, 11th edition, Structured COBOL Programming, John Wiley & Sons, 1998.  Reference Book  M.K.Roy and D. Ghosh Dastidar, COBOL Programming, Tata McGraw Hill, 2001, COBOL—85,2nd Edition.
  • 4. Introduction  Types of computer programs  Operating system programs  Application programs / Software  Types of Processing  Interactive – A point-of-Sale system  Batch processing – Payroll System (Large volume of input at periodic intervals)  COBOL support both type of processing  Customized Application Package: Budget, Scheduling etc.  Machine language programs  Symbolic programs : translates to machine language by
  • 5. Program Development Process  Determine the program specification  Design the program using program planning tools  Code the program  Compile the program  Test the program  Document the program Compile the program Source program in symbolic language Object program in machine language Translated by compiler
  • 6. Test the program  Debug during compile & test phase  Compile time errors: Syntax error e.g. ADD | AD  Misspelled reserved words  Missing punctuation  Execution errors: Logic error e.g. ADD instead of Multiply  Run-Time error: Occurs if computer cannot execute the instruction. E.g.-  Attempt to divide by zero  Reading from a file that cannot be found.
  • 7. Contents  History of COBOL  Features & Language Fundamentals  Program Structure  Coding Format for COBOL Programs  Character Set, Words, Data Names, Literals.
  • 8. Nature of COBOL  popular Business-oriented language  Standard language  English-like language: Standard & business oriented  Relatively easy to understand- User friendly  Reference: http://www.ansi.org
  • 9. History of COBOL  1959 – United States Department of Defense  1960 - COBOL initial specifications presented by CODASYL (COnference on Data SYstems Languages)  1961 – COBOL 61  1964 – BASIC COBOL extended to Visual COBOL  1968 – ANSI (American National Standards Institute) developed American National Standard (ANS) COBOL  1974 – ANSI published revised version of (ANS) COBOL – Business applications needed to manipulate character as well as numeric data – String operations added  1985 – COBOL 85 Standards was introduced with revised version of COBOL-74.
  • 10. COBOL  What does COBOL stand for? COmmon Business Oriented Language.  Which are target area of COBOL applications? Defense, Aircraft, Insurance, Finance, Retail etc. (file & data oriented applications involved)  So we can say that COBOL is basically used for writing business applications and not for developing system software
  • 11. Future of COBOL  COBOL is likely to remain an important language in the years ahead  According to Datapro Information Services Group about 150 billion lines of COBOL source code in use  5 billion new lines added each year  Cobol is used by 42.7% of application programmers in medium to large U.S. companies  $200 million revenues for 2001
  • 12. Year 2000 Problem (Y2K)  Year stored as two digits in older programs to save space  19 assumed as valid prefix for all years  95 represented year 1995  Invalid as prefix for years 2000 and beyond  00 could mean 1900 or 2000
  • 13. Year 2000 Problem (Y2K) Many calculations with dates incorrect starting in 2000  To find your age if you were born in 1970 Subtract 70 from 95 (95 - 70 = 25)  Calculation incorrect for year 2000 and beyond 00 - 70 = -70 when age should be 30
  • 14. Year 2000 Problem (Y2K) To correct problem  Billions of lines of code, many written in COBOL needed to be examined  Code changed to use four digits for year  Age, other calculations now correct 1995 - 1970 = 25 2000 - 1970 = 30 2012 – 1988 = 24
  • 15. Improving Program Design Two techniques used to develop programs that are easier to understand, test, debug and modify  Structured Programming  Top-Down Programming
  • 16. Structured Programming  Eliminates use of GO TO statements  Allowed skipping to different sections of program without returning to starting point  Program logic easier to follow with "GO-TO-less" programming
  • 17. Structured Programming Program divided into paragraphs  Structured programming follows logical control constructs that make program easier to read, modify, and debug.  Main paragraph or module controls logic flow using PERFORM statements  Main module "performs" other modules when instructions in that module required  Each module can be written and tested independently of others
  • 18. Top-Down Programming  Another technique to make programs easier to understand, test, debug and modify  Develop program like term paper  Develop outline first  Add details for each of main steps  Add further refinement for more complex steps
  • 19. Top-Down Programming For COBOL program  Code main modules or routines first  Code intermediate modules next  Details deferred to minor modules and coded last
  • 20. COBOL – Program Structure Principal portions of a program. There are 4 divisions – a) Identification (Required) b) Environment (Optional) c) Data (Optional) d) Procedure (Required) User defined chunk of code which consists of one/more paragraphs. e.g. a) U000-CHECK-LOG SECTION. b) FILE SECTION. User defined chunk of code which consists of one/more sentences. e.g. a) P000-PRINT-FINAL-TOTALS. b) PROGRAM-ID. A SENTENCE consists of one or more statements and is terminated by a full stop. e.g. a) MOVE .21 TO VAT-RATE b) COMPUTE VAT-AMOUNT = PRODUCT-COST * VAT-RATE. PROGRAM DIVISIONS SECTIONS PARAGRAPHS SENTENCES STATEMENTS A STATEMENT consists of a COBOL verb and an operand or operands. e.g. SUBTRACT T-TAX FROM GROSS- PAY GIVING NET-PAY CHARACTERS RESERVED WORDS USER DEFINED WORDS
  • 21. Example IDENTIFICATION DIVISION. PROGRAM-ID. Multiplier. DATA DIVISION. WORKING-STORAGE SECTION. 01 Num1 PIC 9 VALUE ZEROS. 01 Num2 PIC 9 VALUE ZEROS. 01 Result PIC 99 VALUE ZEROS. PROCEDURE DIVISION. DISPLAY "Enter first number (1 digit) : " . ACCEPT Num1. DISPLAY "Enter second number (1 digit) : “. ACCEPT Num2. MULTIPLY Num1 BY Num2 GIVING Result. DISPLAY "Result is = ", Result. STOP RUN.
  • 22. 1. DIVISIONS  A DIVISION is the largest unit in the COBOL program and is a collection of SECTIONs and/or paragraphs. Every COBOL program is divided into four DIVISIONS.  IDENTIFICATION DIVISION  Identifies the program to the computer. It also provide documentation about the program  ENVIRONMENT DIVISION  Define file-names and describe computer equipment used by the program  DATA DIVISION  Describe input and output format used by the program. Also define constants and work areas necessary for processing the data  PROCEDURE DIVISION  Instructions for reading input, processing and creating output
  • 23. 2. SECTIONS  A SECTION is a collection of related paragraphs.  The IDENTIFICATION DIVISION doesn’t contain any SECTIONs, the ENVIRONMENT AND DATA DIVISIONs have pre-defined SECTIONs that you may or may not include, depending on the requirement and the PROCEDURE DIVISION may contain only user defined SECTIONs.  A user defined SECTION is indicated by a user-defined word followed by the reserved word SECTION.  It is used mainly to divide the executable program into units that can be loaded and executed independently.  Thus, a program larger than the memory size can be accommodated in memory.
  • 24. 3. PARAGRAPHS & 4. SENTENCES 3)  A paragraph is a collection of sentences that form a logical unit in a COBOL program.  It is the basic unit of organisation of a COBOL program and is referred by a user-defined name in the program. 4)  A sentence is a sequence of one or more statements, ending with a period.
  • 25. 5. STATEMENTS  A statement is a valid combination of a COBOL verb and its operands.  It specifies an action to be taken by the object program.  The COBOL statements can be broadly classified into two types -  Imperative statements  An imperative statement begins with a verb and specifies an unconditional action to be taken.  Conditional statements.  A conditional statement is one in which the action to be taken is determined by some condition that is evaluated when the program is executed.
  • 26. 6. RESERVED WORDS  A reserved word is a character-string with a predefined meaning in a COBOL source program.  There are several types of reserved words in COBOL.  Keywords:- appear in uppercase.  Eg ADD, READ etc  Optional Words:- They improve readability.  Eg GIVING, AFTER etc  Figurative constants:- Refer to constant values.  Eg ZEROES, SPACES etc
  • 27. 7. USER DEFINED WORDS  They are constructed and used by the application programmer.  They are normally used to define paragraph names, SECTION names, file names, temporary variables, etc.,  The following are the rules for forming user-defined words.  Length may be up to 30 characters.  Only letters, digits and hyphen (-) are allowed.  Embedded blanks are not allowed.  At least one character must be alphabetic.  Cannot be COBOL reserved words.  May not begin or end with hyphen.
  • 28. 8. CHARACTERS  The most basic and indivisible unit of the COBOL language is the character.  The COBOL character set includes 78 characters that can be classified as letters of the alphabet, digits and special Characters.
  • 29. COBOL coding sheet Column numbers 1 2 3 4 5 6 7 8 9 10 11 12 13 14 . . . . . . . 72 80 Column numbers * Area A Area B I D E N T I F I C A T I O N A R E A - /
  • 30. COBOL coding rules  Each line is considered to be made up of 80 columns.  Columns 1 to 6 are reserved for sequence numbers. 1 to 3 ---Page Number. 4 to 6 ---Line Number  Column 7 is an indicator column and has special meaning to the compiler. Hyphen ( - ) indicates continuation. Slash ( / ) indicates comment line , forces page break when printing source listing. Asterisk ( * ) indicates comment line, no such page ejection.  Columns 8 to 11 are called Area A. All COBOL DIVISIONs, SECTIONs, paragraphs and some special entries must begin in Area A.  Columns 12 to 72 are called Area B. All COBOL statements must begin in Area B.
  • 31. COBOL coding sheet Almost all COBOL compilers treat a line of COBOL code as if it contained two distinct areas. These are - AREA A *) Between Column 8 to 11 *) Division, Section, Paragraph names, FD entries & 01 level entries must start in Area A AREA B *) Between Column 12 to 72 *) All Sentences & Statements start in Area B
  • 32. coding rules  Columns 73 to 80 are identification area. Anything written in this area , will be ignored by the compiler but will appear in the source listing.  Columns 1-6 and 73-80 optional and rarely used today  Column 7 for continuation, comment, starting new page  Columns 8-72 for COBOL program statements Column 7 / (slash) forces page break when printing source listing * (asterisk) designates entire line as comment - (dash) to indicate continuation of nonnumeric literal
  • 33. Margin Rules  Columns 8-72 divided into two areas  Area A - columns 8, 9, 10, 11  Area B - columns 12-72  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  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
  • 34.
  • 35.
  • 37. Character Meaning Space + Plus sign - Minus sign or hyphen * Asterisk / Forward slash or solidus = Equal sign $ or £ Currency sign , Comma ; Semicolon . Decimal point or period " Quotation mark ( Left parenthesis ) Right parenthesis > Greater than < Less than A-Z (26) Alphabet (uppercase) a-z Alphabet (lowercase) 0-9 (10) Numeric characters
  • 38. COBOL Words  0-9 , A-Z and - Hyphen  The total no of character must not be greater than 30.  One of the character must be a letter.  A word cannot begin with Hyphen.  A word must not contain a blank or special character except Hyfen (-)  A Cobol word can be User defined or reserve word Valid words Invalid Words GROSS-PAY -Gross- OVERTIME-HOURS OVERTIME HOUR A 1-2-3 B12-4 More than 30 characters
  • 39. Data names and Identifiers  Data names are named memory locations.  Data Names must be described in the DATA DIVISION before they can be used in the PROCEDURE DIVISION.  Can be of elementary or group type.  Can be subscripted for Arrays.  Are user defined words.  Ingle data name or a data name qualified, indexed or subscripted is normally referred to by the general term identifier.  Valid data names: A12 sum-natural net-pay  Invalid: DATA ADD 45 46+2A
  • 40. Rules for forming User-defined words/Data names  Can be at most 30 characters in length.  At least one alphabetic character.  Only alphabets, digits and hyphen are allowed.  Blanks are not allowed.  May not begin or end with a hyphen.  Should not be a COBOL reserved word like ADD,SUBTRACT,MOVE,DISPLAY etc….
  • 41. Data-Name Guidelines 1. Use meaningful data-names that describe contents of field 2. Use prefixes or suffixes in data-names when appropriate • -IN and -OUT for fields (Emp-Salary-IN and Emp-Salary- OUT) • -FILE and -RECORD for file and record names • Emp-File or Emp-Record • Amount-Due-In instead of A1
  • 42. Identify the valid data-names • Identify the valid data-names 1. Date-Of-Birth 2. Amount$Out 3. -First-Name 4. 98-6 5. Time out 6. ADD
  • 43. Literals  Literals are symbols whose value does not change in a program.  A data name may have different values at different points of time whereas a literal means the specific value which remains unchanged throughout the execution of the program. For this reason a literal is often called a constant. Example--- MOVE 0 to sum. (Here 0 is literal)  There are 3 types of literals namely (1) Numeric literals. (2) Non-numeric literals. (3) Figurative constants.
  • 44. Rules for Numeric Literals 1. A numeric literal can be formed with the help of digits only. 2. The maximum number of digits allowed in a numeric literal varies from compiler to compiler. can have a maximum of 18 digits. 3. + or - sign may be included to left of first digit. 4. Decimal point permitted within literal. May not follow last digit. Valid numeric literals 23 , +2359.4 , .125 , -68734
  • 45. Rules for Nonnumeric Literals • Composed of characters which are enclosed within quotation marks. • Generally used for output messages or headings. • Any character in COBOL character set except quotation mark. • The maximum number of characters that are allowed is compiler dependent. ANSI 74: 120 characters. Valid Nonnumeric Literals “123 Main St.” “$14.99” “12,342” “Enter a value from 1 to 10”
  • 46. Figurative Constants  These are literals representing values that may be frequently used by most programs.  These are given some fixed names and when the compiler recognizes these names it sets up the corresponding values in the object program.  Example--- MOVE ZERO TO sum.  MOVE SPACES TO REPORT-REC.  The following is the list of figurative constants and their meanings.
  • 47. Figurative constants Meaning ZERO(S) or ZEROES Represents the value 0, one or more depending on the context SPACE(S) Represents one or more spaces HIGH-VALUE(S) Represents the highest value LOW-VALUE(S) Represents the lowest value QUOTE(S) Represents single or double quotes ALLALL literalliteral Fill With Literal Literals – Figurative Constants
  • 48. Figurative Constants - Examples 01 GrossPay PIC 9(5)V99 VALUE 13.5. MOVE TO GrossPay. 01 GrossPay PIC 9(5)V99 VALUE 13.5. 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 EM I K E  GrossPay 0 0 0 1 3 5 0 
  • 49. Figurative Constants - Examples 01 GrossPay PIC 9(5)V99 VALUE 13.5. MOVE TO GrossPay. 01 GrossPay PIC 9(5)V99 VALUE 13.5. 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 0 0 0 0 0 0 0 
  • 50. Continuation of Lines  A statement or an entry may be continued to the area B of the next line as and when necessary.  A hyphen(-) is used in the indicator field for continuation of lines.  Actually, a hyphen in the indicator field means that the first non- blank character in the area B of the current line is the character immediately following the last non-blank character of the previous line.  Example—In case of non numeric literal Indicator line Area A Area B Continued line “Enter the Continuation Line - “Number”.
  • 51.  Is Cobol still used ?  75% of all business data is processed in COBOL.  There are between 180 billion and 200 billion lines of COBOL code in use worldwide.  15% of all new applications (5 billion lines) through 2009 will be in COBOL.

Notas del editor

  1. During the 1950s, the western parts of the world experienced a tremendous need for a high level programming language suitable for business data processing. To meet this demand the U.S. Dept of Defence convened a conference on the 28th and 29th of May, 1958 to highlight and stress the importance of a high-level business data processing language. The conference led to the formation of a team called CODASYL (Conference On DAta Systems Language). This team had representatives from civil and governmental organisations, academics, computer manufacturers and other software enthusiasts to work towards the goal. As a result, a new language called COBOL (COmmon Business Oriented Language) was developed in September 1959. This was released with some minor modifications in April 1960. On May 5, 1961, COBOL-61 was published with some more revisions. It is this version which provided the foundation for later versions. In 1965, a re-revised version of COBOL was released with a number of additional features. However, it was only in 1968 that COBOL was approved by ANSI (American National Standards Institute) as a standard language for commercial use. This version of COBOL is known as COBOL-68. The next revised official standard was released in 1974 and is known as COBOL-74.
  2. What does COBOL stand for? CO mmon B usiness O riented L anguage. Which are target area of COBOL applications? Defense, Aircraft, Insurance, Finance, Retail etc (file &amp; data oriented applications involved) So we can say that COBOL is basically used for writing business applications and not for developing system software
  3. The Constituents of a COBOL Program – DIVISIONS A DIVISION is the largest unit in the COBOL program and is a collection of SECTIONs and/or paragraphs. Every COBOL program is divided into four DIVISIONs viz. IDENTIFICATION DIVISION, ENVIRONMENT DIVISION, DATA DIVISION and PROCEDURE DIVISION. SECTIONS A SECTION is a collection of related paragraphs. The IDENTIFICATION DIVISION doesn’t contain any SECTIONs, the ENVIRONMENT AND DATA DIVISIONs have pre-defined SECTIONs that you may or may not include, depending on the requirement and the PROCEDURE DIVISION may contain only user defined SECTIONs. A user defined SECTION is indicated by a user-defined word followed by the reserved word SECTION. It is used mainly to divide the executable program into units that can be loaded and executed independently. Thus, a program larger than the memory size can be accommodated in memory. PARAGRAPHS A paragraph is a collection of sentences that form a logical unit in a COBOL program. It is the basic unit of organisation of a COBOL program and is referred by a user-defined name in the program. SENTENCES A sentence is a sequence of one or more statements, ending with a period. STATEMENTS A statement is a valid combination of a COBOL verb and its operands. It specifies an action to be taken by the object program. The COBOL statements can be broadly classified into two types viz. Imperative statements and Conditional statements. An imperative statement begins with a verb and specifies an unconditional action to be taken. On the other hand, a conditional statement is one in which the action to be taken is determined by some condition that is evaluated when the program is executed. RESERVED WORDS A reserved word is a character-string with a predefined meaning in a COBOL source program. There are several types of reserved words in COBOL. 1) Keywords :- appear in uppercase. Eg ADD, READ etc 2) Optional Words :- They improve readability. Eg GIVING, AFTER etc 3) Figurative constants :- Refer to constant values. Eg ZEROES, SPACES etc USER DEFINED WORDS They are constructed and used by the application programmer. They are normally used to define paragraph names, SECTION names, file names, temporary variables, etc., The following are the rules for forming user-defined words. 1) Length may be up to 30 characters. 2) Only letters, digits and hyphen (-) are allowed. 3) Embedded blanks are not allowed. 4) At least one character must be alphabetic. 5) Cannot be COBOL reserved words. 6) May not begin or end with hyphen. CHARACTERS The most basic and indivisible unit of the COBOL language is the character. The COBOL character set includes 78 characters that can be classified as letters of the alphabet, digits and special characters.
  4. COBOL CODING RULES a) Each line is considered to be made up of 80 columns. b) Columns 1 to 6 are reserved for line numbers. c) Column 7 is an indicator column and has special meaning to the compiler. It can have - i) Asterisk ( * ) indicates comments ii) Hyphen ( - ) indicates continuation iii) Slash ( / ) indicates form feed d) Columns 8 to 11 are called Area A. All COBOL DIVISIONs, SECTIONs, paragraphs and some special entries must begin in Area A. e) Columns 12 to 72 are called Area B. All COBOL statements must begin in Area B. f) Columns 73 to 80 are identification area.
  5. Almost all COBOL compilers treat a line of COBOL code as if it contained two distinct areas. These are - AREA A *) Between Column 8 to 11 *) Division, Section, Paragraph names, FD entries &amp; 01 level entries must start in Area A AREA B *) Between Column 12 to 72 *) All Sentences &amp; Statements start in Area B
  6. DATA NAMES *) Data-names are named memory locations. They must be described in the DATA DIVISION before they can be used in the PROCEDURE DIVISION. *) They can be of elementary or group type and further can be qualified or subscripted. *) They are user-defined words.
  7. RULES FOR FORMING USER-DEFINED WORDS USER DEFINED WORDS need to be as per the following rules - 1) They are used to form section, paragraph and data names. 2) They can be at most 30 characters in length. 3) Only alphabets, digits and hyphen are allowed. 4) Blanks are not allowed. 5) They may not begin or end with a hyphen. 6) They should not be a COBOL reserved word.
  8. LITERALS A Literal is a symbol whose value does not change in a program. It is also known as constant. There are three types of literals in COBOL namely – a) Numeric literal b) Non-numeric literal c) Figurative constant
  9. FIGURATIVE CONSTANTS FIGURATIVE CONSTANTS are reserved words that refer to specific constant values. The following are figurative constants and their meanings. ZERO/ZEROS/ZEROES Represents the numeric value zero (0), or one or more occurrences of the nonnumeric character zero (0), depending on context. When the context cannot be determined, a nonnumeric zero is used. SPACE/SPACES Represents one or more blanks or spaces. SPACE is treated as a nonnumeric literal. HIGH-VALUE/HIGH-VALUES Represents one or more occurrences of the character that has the highest ordinal position in the collating sequence used. For the EBCDIC collating sequence, the character is X&apos;FF&apos;; for other collating sequences, the actual character used depends on the collating sequence indicated by the locale. Note that HIGH-VALUE is treated as a nonnumeric literal. LOW-VALUE/LOW-VALUES Represents one or more occurrences of the character that has the lowest ordinal position in the collating sequence used. For the EBCDIC collating sequence, the character is X&apos;00&apos;; for other collating sequences, the actual character used depends on the collating sequence indicated by the locale. Note that LOW-VALUE is treated as a nonnumeric literal. QUOTE/QUOTES Represents one or more occurrences of the quotation mark character (&quot;). QUOTE or QUOTES cannot be used in place of a quotation mark to enclose a nonnumeric literal.