COBOL Basics
Character set
In hierarchy 'Characters' are the lowest. They cannot divide further.
In COBOL character set consists of following characters:
Characters | Description |
---|
A to Z | Alphabets in Upper case |
a to z | Alphabets in Lower case |
0 to 9 | Numeric |
+ | 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:
Position | Field | Description |
---|
1 to 6 | Column Numbers | 1 to 3 is reserved for page number. 4 to 6 is reserved for line numbers. |
7 | Indicator | It can have (* , - , /). Asterisk(*) indicates comments, Hyphen(-) indicates continuation, Slash (/) indicate form feed. |
8 to 11 | Area A | All the COBOL divisions, sections, paragraphs and special entries must start in Area A. |
12 to 72 | Area B | All COBOL statements should start in area B. |
73 to 80 | Identification Area | It 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:
Valid | Invalid |
---|
'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.
Valid | Invalid |
---|
200 | 2,00 |
+15.9 | 15. |
-3.9 | 3.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