COBOL - Introduction
-
Upload
jasmin-fernando -
Category
Documents
-
view
331 -
download
24
Transcript of COBOL - Introduction
COBOL (Common Business Oriented Language)
Introduction
History
1959 – Conference on Data System Languages (CODASYL)
created the first standardized business computer programming language
1960 – First proposal for COBOL – named COBOL-60
History
1961 – First COBOL compilers are getting used
1965 – The usage of COBOL starts to increase a lot (COBOL edition
1965).
History
1968 – The American National Standards Institute (ANSI) sets the first official COBOL: COBOL-68.
1970 – The International Organization for Standardization (ISO) makes ANSI’s COBOL-68 an
international standard.
History
1973 – Machine Independent COBOL presented.
1974 – ANSI published a revised version of (ANSI) COBOL, COBOL-74.
1985 – The new COBOL-85 standard is set (ANSI X3.23-1985).
History
1989 – Intrinsic functions are added to the standard (ANSI
X3.23a- 1989). 1997 – Object-oriented features are
added to Structured COBOL.
History
2002 – The long awaited object oriented COBOL 2002 standard is set.
– Information on 2008 COBOL standard at http://www.ansi.org
Features
As a programming language Oriented towards business applications Supports Procedural Programming (from
COBOL-60) Supports Structured Programming (from
COBOL-68)
Features
As a programming language Supports Machine Independent
Programming (from COBOL-73) Supports Object oriented programming
(from COBOL-2002)
Features
As a high-level language English like Problem oriented Self-documenting Multi-platform support Easy to learn/read/write and maintain
Program Structure
PROGRAM
DIVISIONS
SECTIONS
PARAGRAPHS
ENTRY SENTENCES
STATEMENTCLAUSE
PHRASEWORDS CHARACTERS
Character Set
Digits (10) 0, 1-9 Letters (26) A, B…Z Blank Space (01) b Symbols (12) + - * / , . ( ) = $ ; “ Conditional (02) < >
Total: 51 Characters in COBOL-74
Character Set
Reference Modifier (01) :Total: 52 Characters in COBOL-85
Apostrophe (01) ‘Total: 53 Characters in Mainframe COBOL
Note: Mainframe COBOL also includes small letters (a to z), for nonnumeric literals.
Reserved Words
Keywords The spelling of words are American
English and not British COBOL supports abbreviations in many
cases
User Defined Words
Should not be a Reserved Word 1 - 30 characters Letters, digits, hyphens (-) only At least one Letter or Hyphen
(Recommended to use the first character as an alphabet)
User Defined Words
Hyphen/s should be embedded. Spaces are not allowed. Must be unique within a set
Literals
User defined constants Can be Numeric literal, Floating point
literal and Non-numeric literal
Note : A non-numeric literal can hold a character which is not available in COBOL character set.
Literals
Numeric Literals May consist of numerals decimal point (.)
1 decimal character is allowed Should not be the rightmost character
plus or minus sign 1 sign character (+ or -) is allowed Leftmost character
Not enclosed in quotes
Literals
Numeric Literals
123 123.45 -256 +2987
Examples
Literals
Floating Point Literals Support a much wider range of values
than numeric literal
In Mathematics In COBOL12345000 1.2345*107 1.2345E07 or
+12.345E+06
Example
Literals
Non-Numeric Literals Enclosed in quotes (“) May consists of alphanumeric characters 1 – 160 characters An embedded quotation mark must be
represented by a pair of quotation marks (“ “)
Literals
Non-Numeric Literals The opening delimiter (“) cannot split
across lines.
Note: COBOL-74 compilers accept only 120 characters.
Figurative Constants
Predefined constants, but reserved words
Except ZERO/ZEROES, others are treated as Non-Numeric Literals
Figurative Constants
ZERO, ZEROS, ZEROES (0)QUOTE, QUOTES (“)SPACE, SPACESALL Represents 1 or more occurrences of
the string*Not used in Mainframe
Examples
Figurative Constants
NULL, NULLS To indicate an invalid address for a POINTER variable;Has the value Zero in Mainframe COBOL
Examples
Figurative Constants
HIGH-VALUE, HIGH-VALUES Highest value in the collating sequence
Examples
Figurative Constants
LOW-VALUE, LOW-VALUES Lowest ordinal position in the collating sequence
Examples
Figurative Constants
NOTES: The singular and plural forms of a figurative
constant can be used interchangeably.Do not use QUOTE/QUOTES to enclose a Non-numeric literal.ZERO, ZEROS, ZEROES are considered as Numeric Literals.
Special Registers
Reserved words that name storage areas generated by the compiler
Special Registers
RETURN-CODE Used to pass a return code to the calling
program or to the JCL when the current COBOL program ends
Examples
Special Registers
WHEN-COMPILED Contains the date at the start of the program compilation
Examples
Operators
Arithmetic Operators Relational Operators Logical Operators
Note: All COBOL operators must be preceded and followed by a space.
Operators
Arithmetic Operators Binary Operators
Addition + Subtraction - Multiplication * Division / Exponentiation **
Operators
Arithmetic Operators Unary Operators
Positive + (Equals to Multiplication by +1) Negative - (Equals to Multiplication by +1)
Operators
Relational Operators Less Than < Greater Than > Equal To = Less Than or Equal To <= Greater Than or Equal To >=
Note: Each relational operators can be combined with the NOT logical operator
Operators
Logical Operators Conjunction AND Inclusive OR Negation NOT
Separator String
A word formed by 2 or more contiguous characters
1st character is a special character and the 2nd character is a space.
Separator String
Separator comma ,bSeparator period .bSeparator Semicolon ;b
Note: b indicates a blank space.
Examples
Separator String Rules
A COBOL statement may use Separator Period or
Separator Comma or Separator Semicolon.
Separator String Rules
The following must end with a separator period: Sentence File (FD), sort/merge file (SD) and data description
entries in the data division Each paragraph in the Identification division
Separator String Rules
The following must end with a separator period: SOURCE-COMPUTER, OBJECT-COMPUTER,
SPECIAL-NAMES and I-O-CONTROL paragraphs in the Environment division
Each file-control entry in the FILE-CONTROL paragraph
Separator String Rules
The following must end with a separator period: All the 4 division headers All the section headers
Phrase & Clause
Phrase – “meaningless” collection of COBOL words Clause – collection of words or phrases that itself has a meaning like
Statements
Phrase & Clause
Phrase
AT END UNTIL A > B
Clause
OCCURS 5 TIMES LABEL RECORDS ARE STANDARDS
Examples
Examples
Statement & Clause
Statements – group of words and/or phrases in PROCEDURE DIVISION
Clause – group of words and/or phrases in DATA, ENVIRONMENT &
IDENTIFICATION DIVISION
Sentence & Entry
Sentence – collection of statements Entry – collection of clauses
Sentence & Entry
Must be terminated by a Separator Period A COBOL Sentence can have only one
COBOL Statement
Paragraphs
Subgroup of Sections
Paragraphs
2 types: Predefined
IDENTIFICATION DIVISION & ENVIRONMENT DIVISION have only predefines paragraphs
User defined PROCEDURE DIVISION allows to define user defined paragraphs
Paragraphs
Paragraph header has the para-name followed by a separator period.
At least one paragraph should be specified in PROCEDURE DIVISION, if it has any sentences.
Sections
Subgroup of Divisions
Sections
2 types: Predefined
ENVIRONMENT DIVISION & DATA DIVISION have only predefines sections User defined
PROCEDURE DIVISION allows to define user defined sections
Sections
A section header has the: Section-name Followed by a space The word SECTION A separator period
Sections
Optional, but must be specified in ENVIRONMENT DIVISION and DATA DIVISION, if they have appropriate entries
COBOL Coding Sheet
Cols 1 – 6 : Sequence Number / Line Number Area, Margin L is Column 1 : Originally designed for entering line numbers on Punch Cards
1 – 6 7 8 – 11 12 – 72Sequence No. Indicator No. Area A Area B
COBOL Coding Sheet
Cols 1 – 6 : Used to label a source statement like revision number : Can consist of any characters : Nothing to do inside the program
1 – 6 7 8 – 11 12 – 72Sequence No. Indicator No. Area A Area B
COBOL Coding Sheet
Col 7 : Can have the ff: * - designates entire line as comment - - indicates continuation of nonnumeric literal / - forces page break when printing source listing : Also known as Margin C
1 – 6 7 8 – 11 12 – 72Sequence No. Indicator No. Area A Area B
COBOL Coding Sheet
Col 7 : A D or d indicates a debugging line : Should be left blank if this line is not a comment/ debugging line/ page break or a continuation.
1 – 6 7 8 – 11 12 – 72Sequence No. Indicator No. Area A Area B
COBOL Coding Sheet
Cols 8 – 72 : For COBOL program statements
1 – 6 7 8 – 11 12 – 72Sequence No. Indicator No. Area A Area B
COBOL Coding Sheet
Cols 8 – 11 : Area A / Margin A is column 8
: The following items must begin in Area A:- Division headers- Section headers
1 – 6 7 8 – 11 12 – 72Sequence No. Indicator No. Area A Area B
COBOL Coding Sheet
Cols 8 – 11 : The following items must begin in Area A:- Paragraph-names- Level indicators FD & SD- Level-numbers 01 and 77
1 – 6 7 8 – 11 12 – 72Sequence No. Indicator No. Area A Area B
COBOL Coding Sheet
Cols 8 – 11 : The following items must begin in Area A:
- DECLARATIVES and END DECLARATIVES
- End Program statement
1 – 6 7 8 – 11 12 – 72Sequence No. Indicator No. Area A Area B
COBOL Coding Sheet
Cols 12 – 72 : Area B / Margin B is column 12 and Margin R is
column 72
1 – 6 7 8 – 11 12 – 72Sequence No. Indicator No. Area A Area B
COBOL Coding Sheet
Cols 12 – 72 : The following items must begin in Area B:
- Entries & Sentences- Statements &
Clauses- Continuation lines
1 – 6 7 8 – 11 12 – 72Sequence No. Indicator No. Area A Area B
COBOL Coding Sheet
Note : Anything that begins anywhere in Area A
or B is considered to be in Area A or B respectively.
Level Numbers other than 01 & 77 can begin in Area A or Area B.
1 – 6 7 8 – 11 12 – 72Sequence No. Indicator No. Area A Area B
COBOL Coding Sheet
Cols 73 – 80 : Identification Field (used in punch cards, but no more!)
Note : 80 columns can COBOL accepts and only the first 72 columns are used by the COBOL compiler.
1 – 6 7 8 – 11 12 – 72Sequence No. Indicator No. Area A Area B
Sample COBOL Program---1----+----2----+----3----+----4----+----5----+----6----+----7----+----8 IDENTIFICATION DIVISION. PROGRAM-ID. SequenceProgram. AUTHOR. Michael Coughlan.*This prgram lets the user to input 2 numbers to be multiplied and display*the product.
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. CalculateResult. ACCEPT Num1. ACCEPT Num2. MULTIPLY Num1 BY Num2 GIVING Result. DISPLAY "Result is = ", Result. STOP RUN.
Reading the Syntax Diagrams Words in uppercase are reserved words.
When underlined they must be present when the operation of which they are a part is used. When they are not underlined the used for readability only and are optional. If used they must be spelt correctly.
Reading the Syntax Diagrams Words in lower case represent names which will be devised by the programmer.
Reading the Syntax Diagrams When enclosed in braces { }
A choice must be made from the options within the braces. When enclosed in square brackets [ ]
Indicates that the material is an option
Reading the Syntax Diagrams The ellipsis symbol ‘...’ indicates that the preceding syntax element may be repeated at the programmer’s discretion.