COBOL Basics

Character set

In hierarchy 'Characters' are the lowest. They cannot divide further.

In COBOL character set consists of following characters:

CharactersDescription
A to ZAlphabets in Upper case
a to zAlphabets in Lower case
0 to 9Numeric
+Plus sign
*Asterisk
Space
-Hyphen or minus
,Comma
$Currency sign
.Period or Decimal point
;Semicolon
(Left parenthesis
)Right parenthesis
Quotation marks
>Greater than
<Less than
'Apostrophe
=Equal sign
:Colon

Coding sheet in COBOL

  • The source program code of COBOL should be written in an acceptable format to the compiler.
  • The code of COBOL program is written in coding sheets.
  • In every line of coding there are 80 character positions.
The positions of characters are grouped into the following fields:

PositionFieldDescription
1 to 6Column Numbers1 to 3 is reserved for page number. 4 to 6 is reserved for line numbers.
7IndicatorIt can have (* , - , /). Asterisk(*) indicates comments, Hyphen(-) indicates continuation, Slash (/) indicate form feed.
8 to 11Area AAll the COBOL divisions, sections, paragraphs and special entries must start in Area A.
12 to 72Area BAll COBOL statements should start in area B.
73 to 80Identification AreaIt can be used by the programmer as per the need.

Character String

  • By merging individual characters, character strings are formed.
  • Character string can be comment, literal or COBOL word.
  • All the character strings end with separators.
  • Comma, space, period, apostrophe, etc. are the frequently used separators.

Comment

  • A comment is a character string. It does not affect the execution of the program.
  • The comment can be any combination of characters.
Following are the two types of comments:

Comment Line
  • Comment line written in any column.
  • For the comment line compiler does not check for syntax and treat for documentation.
Comment Entry
  • Comment entries are included in the optional paragraph of an identification division.
  • These entries are written in Area B i.e the positions from 12 to 72 and programmers use it for reference.

Literal

Literal is a constant which is directly specified in a program with their values.

Following are the types of literals:

a) Alphanumeric Literal
  • Alphanumeric literal are enclosed in apostrophe or quotes.
  • The starting and the ending literal should be same.
  • The length can be up to 160 characters.
For example:

ValidInvalid
'It is valid''It is not valid”
“It is valid”“It is not valid'
'It doesn' 't invalid''It doesn't valid'

b) Numeric Literal
  • It is a combination of digits from 0 to 9, + , - or decimal point.
  • The length of it is up to 18 characters.
  • The rightmost character cannot be a sign.
  • Decimal point should not occur at the end.
ValidInvalid
2002,00
+15.915.
-3.93.9-

COBOL Word

  • COBOL word is a character string. It can be user defined reserved word.
  • The length of COBOL word is up to 30 characters.
User defined
  • Naming files, data, paragraph, records, names and sections are the purposes for which user defined words are used.
  • While forming the user defined word alphabets, digits and hyphens are allowed.
  • COBOL reserved words should not be used as a user defined word.
Reserved words
Reserved words are the predefined words in COBOL.

Following are the various reserved words often used in COBOL:
  • Keywords like ADD, MOVE, ACCEPT etc.
  • Special character words like *, +, - , >=, etc.
  • Figurative constants are constant values like SPACE, ZERO, etc.
Following are the constant values of figurative constant:
  • HIGH-VALUES
  • LOW-VALUES
  • QUOTES
  • ZERO/ZEROES
  • SPACES
  • ALL literal