Sie sind auf Seite 1von 18


COBOL – Common Business Oriented

Session 1: Learning Objectives

Explain COBOL Language Structure

Nagaraju Domala
COBOL Language Structure

Identification Environment Data Procedure

Division Division Division Division

Sections Sections Sections

Reference Format
Paragraphs Paragraphs Paragraphs

Entries Entries Entries Sentences

Clauses Clauses Clauses Statements

Phrases Phrases Phrases

Character Sets

Nagaraju Domala
COBOL Language Structure - Divisions
Identification Division – Identifies the program, programmer name
and other optional information

Environment Division – Describes the Physical Environment in

which the program executes. Identifies input and output devices.

Data Division – Describes the data used by the Program

Procedure Division – Business Logic is coded here

Nagaraju Domala
COBOL Language Structure – Basic Character Set

Category Values
Alphabet (Upper Case) A-Z
Alphabet (Lower Case) a-z
Numeric 0-9

Special Characters
Space + - * / = $

Total Characters in the Basic Character Set = 79.

Nagaraju Domala
COBOL Language Structure – Coded Character Set

 While Basic character set is used to create syntactic elements of the

language (ie., reserved words, sentences, paragraphs etc), Coded
Character Set is used to encode the data handled.
 A Coded Character Set is the coded representation of a set of
characters, where each character is assigned a numerical position.
 IBM uses EBCDIC format for character encoding. This is also called
Single Byte Character Set (each character takes one byte).
 For multilingual support* IBM uses EBCDIC DBCS character encoding
(Each character takes 2 bytes).
 Other encoded formats are ASCII and UTF16 (Unicode).
 Unicode is supported by IBM COBOL for Unix and Web programming.
 As an Example the letters 'a' and 'A' are same in Basic Character set,
where as they are different in EBCDIC or ASCII representations

Nagaraju Domala
COBOL Language Structure – Character-strings

A character-string is a character or a sequence of contiguous

characters that forms a COBOL word, a literal, a PICTURE
character-string, or a comment-entry.
A character-string is delimited by separators.

COBOL Words Literals Comments

Reserved User-defined
Function-names System-names
Words Words

Key Optional Figurative Special Special Special

Words Words Constants Registers Object Character
Identifiers Words

Nagaraju Domala
COBOL Language Structure – Reserved
 A reserved word is a character-string with a predefined
meaning in a COBOL source unit.
There are six types of reserved words:
Keywords - required within a given clause, entry, or statement.
Optional words - included in the format of a clause, entry, or statement in
order to improve readability. No effect on program execution.
Figurative constants - name and refer to specific constant values.
Special character words - Arithmetic and Relational operators
Special object identifiers - Used in OO programming
Special registers - named storage areas generated by the compiler.

Nagaraju Domala
COBOL Language Structure – User
Defined Words
 The maximum size of a COBOL user-defined word is 30 bytes.
 Except for arithmetic operators and relation characters, each character of a
COBOL word is selected from the following set:
 A through Z
 a through z
 0 through 9
 - (hyphen)

 The hyphen cannot appear as the first or last character.

 Must contain at least one alphabetic character (except section-names,
paragraph-names, priority-numbers, and level-numbers)
 A reserved word cannot be used as a user-defined word or as a system-

Nagaraju Domala
COBOL Language Structure – Literals*

 A literal is the value of a data item.

• Alphanumeric Literals
• Character string of maximum length is 160 bytes, minimum is 1 byte.
• Each character can be from any EBCDIC character set
• Delimited by either Quotes or Apostrophes. Both starting and ending delimiter
should be same.

• Numeric Literals
• Character string formed with digits 0 – 9, signs + or -, and a decimal point

Nagaraju Domala
COBOL Language Structure – Picture Strings*

Picture String is an important concept, specific to COBOL.

Picture Strings are used in defining the data items of various
Picture String describes how the value of data item appears
when printed.
Ex. W-Name PIC x(6) Value "George".
W-Salary PIC S999999.99 Value 5000.00.

X(6) and S999999.99 are Picture Strings.

W-Name, W-Salary are data items, “George” is alphanumeric literal, 5000.00 is numeric
literal Value is a reserved word.

Nagaraju Domala
COBOL Language Structure – Comments
 Comments are additional text in the COBOL program that
has no impact on the program and is ignored by the
 Comments are used to document the program.

Nagaraju Domala
COBOL Language Structure – Separators

A separator is a character or a string of two or more

contiguous characters that delimits character-strings.

used Space , . ; ( ) : “ `

Additional Separators are used for Multilingual, National Character and

Pseudo Text support

Nagaraju Domala
COBOL Language Structure

A section is a block of code usually containing zero, one or more paragraphs. A

section begins with the section name and ends where the next section name is
encountered. A section name is followed by the word SECTION.

A paragraph is a block of code made up of zero, one or more sentences. A

paragraph begins with the paragraph name and ends with the next paragraph
or section name

A sentence consists of one or more statements and is terminated by a period.

A statement is where one or more actions are performed. The statement

contains a verb followed by phrases.

Nagaraju Domala
COBOL Language Structure

An entry is a series of clauses that ends with a separator period. Entries are
constructed in the identification, environment, and data divisions.

A clause is an ordered set of consecutive COBOL character-strings that

specifies an attribute of an entry. Clauses are constructed in the identification,
environment, and data divisions.

Each clause or statement in a program can be subdivided into smaller units

called phrases.

Nagaraju Domala
COBOL Language Structure - Reference Format
 Traditionally, COBOL programs were written on coding forms and then
punched on to punch cards
 The first six character positions are reserved for sequence numbers.
 Column 7 is used for special purpose
 An entire line can be designated as comment by placing a *
 While printing, Source listing can be ejected to a new page by placing a ‘/’
 Used for continuation of non numeric literals by placing a ‘-’
 Used for Debugging lines by placing 'D'
 Columns 8-72 are used to write the coding instructions
 Columns 73-80 are not part of reference format. However, in some cases
these positions are used to identify the programmer who changed specific
portions of the code. Compiler ignores this portion.

Nagaraju Domala
COBOL Language Structure - Reference Format

 Columns 8-11 is called Area A or Margin A

 Columns 12-72 is called Area B or Margin B

 Entries of Area A should start between the columns 8-11 and can
extend to Area B

 Entries of Area B should start between columns 12-72

 All division names, section names, paragraph names, FD entries

and 01 level numbers must start in Area A.

 All other sentences must start in Area B.

Nagaraju Domala
COBOL coding sheet

Nagaraju Domala