|
2. COBOL Basics
2.1 Coding Areas
If you look at the COBOL coding in later sections
(e.g. League Table program in the Sample code section) the specific positions of coding elements are important
for the compiler to understand. Essentially, the first 6 spaces are ignored
by the compiler and are usually used by the programmer for line numbers.
These numbers are not the same as those in BASIC where the line
number is used as part of the logic (e.g. GOTO 280, sending the logic to
line 280).
The seventh position is called the continuation
area. Only certain characters ever appear here, these being:
Positions 8 to 11 and 12 to 72 are called area
A and area B, respectively. These are used in specific instances
that will be detailed in later sections.
Identifier names User-defined names must conform to the following rules:
A123
Like all COBOL code, the compiler will not distinguish
between upper and lower case letters (except within quotes).
Lastly, COBOL has a large list of reserved words
that cannot be used as identifier names. A list of COBOL reserved words
is given elsewhere.
Punctuation
The full stop (period) is the most important punctuation
mark used, and its use will be detailed later (see Scope terminators).
Generally, every line of the IDENTIFICATION, ENVIRONMENT, and DATA DIVISION end in a period.
Quotation marks, either single or double, are used
to surround quoted literals (and when calling a sub-program). However,
donât mix them when surrounding the literal, e.g.
" This is bad â
" but this is ok "
Commas and semi-colons are also used to separate lists of identifiers, e.g. Spelling
Since COBOL was developed in the USA, the spelling
of words is American, e.g. INITIALIZE or ORGANIZATION (using Z rather than
S). Brits be warned!
In many cases, abbreviations and alternative spellings
are available (see reserved word list), e.g. ZERO ZEROS ZEROES all mean
the same thing. Likewise, LINE and LINES, PICTURE and PIC, THROUGH and
THRU.
As is traditional for all introductory lessons for
a programming language, here's a 'Hello World' program:
| ||||||