COBOL - Introduction

of 72/72
COBOL (Common Business Oriented Language)
  • date post

    26-Nov-2014
  • Category

    Documents

  • view

    317
  • download

    23

Embed Size (px)

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 StandardsInstitute (ANSI) sets the first official COBOL: COBOL-68. 1970 The International Organization for Standardization (ISO) makes ANSIs 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 tothe standard (ANSI X3.23a1989). 1997 Object-oriented features are added to Structured COBOL.

History

2002 The long awaited object orientedCOBOL 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 (fromCOBOL-60) Supports Structured Programming (from COBOL-68)

Features

As a programming language Supports Machine IndependentProgramming (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 StructurePROGRAM DIVISIONS SECTIONS PARAGRAPHS ENTRY CLAUSE PHRASE WORDS CHARACTERS SENTENCES STATEMENT

Character Set

Digits Letters Blank Space Symbols Conditional

(10) (26) (01) (12) (02)

0, 1-9 A, BZ b +-*/,.()=$;

Total: 51 Characters in COBOL-74

Character Set

Reference Modifier (01) Apostrophe(01)

:

Total: 52 Characters in COBOL-85 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 pointliteral 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 LiteralsExamples

123 123.45 -256 +2987

Literals

Floating Point Literals Support a much wider range of values

than numeric literal

Example In Mathematics 12345000 1.2345*107 In COBOL 1.2345E07 or +12.345E+06

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 ConstantsExamples

ZERO, ZEROS, ZEROES (0) QUOTE, QUOTES () SPACE, SPACES ALL Represents 1 or more occurrences of the string *Not used in Mainframe

Figurative ConstantsExamples

NULL, NULLS

To indicate an invalid address for a POINTER variable; Has the value Zero in Mainframe COBOL

Figurative ConstantsExamples

HIGH-VALUE, HIGH-VALUES Highest value in the collating sequence

Figurative ConstantsExamples

LOW-VALUE, LOW-VALUES

Lowest ordinal position in the collating sequence

Figurative ConstantsNOTES: 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 storageareas generated by the compiler

Special RegistersExamples

RETURN-CODE

Used to pass a return code to the calling program or to the JCL when the current COBOL program ends

Special RegistersExamples

WHEN-COMPILED Contains the date at the start of the program compilation

Operators

Arithmetic Operators Relational Operators Logical OperatorsNote: 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 contiguouscharacters 1st character is a special character and the 2nd character is a space.

Separator StringExamples

Separator comma Separator period Separator Semicolon

,b .b ;b

Note: b indicates a blank space.

Separator String Rules

A COBOL statement may useSeparator Period or Separator Comma or Separator Semicolon.

Separator String Rules

The following must end with aseparator 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 aseparator period: SOURCE-COMPUTER, OBJECT-

COMPUTER, SPECIAL-NAMES and I-OCONTROL paragraphs in the Environment division Each file-control entry in the FILECONTROL paragraph

Separator String Rules

The following must end with aseparator 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

PhraseExamples

AT END UNTIL A > B

ClauseExamples

OCCURS 5 TIMES LABEL RECORDS ARE STANDARDS

Statement & Clause

Statements group of words and/or Clause

phrases in PROCEDURE DIVISION 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 Sheet16 7 8 11Area A

12 72Area B

Sequence No. Indicator No.

Cols 1 6 : Sequence Number / Line

Number Area, Margin L is Column 1 : Originally designed for entering line numbers on Punch Cards

COBOL Coding Sheet16 7 8 11Area A

12 72Area B

Sequence No. Indicator No.

Cols 1 6 : Used to label a source

statement like revision number : Can consist of any characters : Nothing to do inside the program

COBOL Coding Sheet16 7 8 11Area A

12 72Area B

Sequence No. Indicator No.

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

COBOL Coding Sheet16 7 8 11Area A

12 72Area B

Sequence No. Indicator No.

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.

COBOL Coding Sheet16 7 8 11Area A

12 72Area B

Sequence No. Indicator No.

Cols 8 72 : For COBOL program

statements

COBOL Coding Sheet16 7 8 11Area A

12 72Area B

Sequence No. Indicator No.

Cols 8 11 : Area A / Margin A is column

8 : The following items must begin in Area A:- Division headers - Section headers

COBOL Coding Sheet16 7 8 11Area A

12 72Area B

Sequence No. Indicator No.

Cols 8 11 : The following items must

begin in Area A:

- Paragraph-names - Level indicators FD & SD - Level-numbers 01 and 77

COBOL Coding Sheet16 7 8 11Area A

12 72Area B

Sequence No. Indicator No.

Cols 8 11 : The following items must

begin in Area A:

- DECLARATIVES and END DECLARATIVES - End Program statement

COBOL Coding Sheet16 7 8 11Area A

12 72Area B

Sequence No. Indicator No.

Cols 12 72 : Area B / Margin B is column

12 and Margin R is column 72

COBOL Coding Sheet16 7 8 11Area A

12 72Area B

Sequence No. Indicator No.

Cols 12 72 : The following items must

begin in Area B:

- Entries & Sentences - Statements & Clauses - Continuation lines

COBOL Coding Sheet16 7 8 11Area A

12 72Area B

Sequence No. Indicator No.

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.

COBOL Coding Sheet16 7 8 11Area A

12 72Area B

Sequence No. Indicator No.

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.

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 reservedwords. 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 nameswhich 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 programmers discretion.