COBOL - Coding Sheet
In the earlier days, the COBOL program needs to punch on the card, and it will be loaded to punch card readers.
There was a need for a coding sheet to recognize the program coding by the punch card reader.
The coding sheet was a structure to identify from where the COBOL coding statements punched/started writing to differentiate the statements from others.
In nowadays, punched cards are replaced by new editors but the same coding sheet using to code the COBOL programs.
In short, we can say that the COBOL program must be written in a format acceptable to the compilers. There is a total of 80 character positions on each line of a coding sheet.
Character positions are grouped into the following sections:
Let's see the example given below, showing a COBOL coding sheet:
When you compile and execute the code, it will display the following output:
Characters are the lowest in the COBOL hierarchy, and they cannot be further divided. The following COBOL characters are given below:
A character string is a collection of individual characters. A character string can be a:
A comment is called a character string that does not affect the execution of a program. It can be any combination of characters.
There are two types of comments:
We can write the comment line in any column. The compiler does not check a comment line for syntax and use it for documentation.
Comment entries are those, which are integrated into the optional paragraphs of an identification Division. They are written in Area B, and programmers make use of it for reference.
Let's see one example for types of comments:
It will look like this in your OpenCobolIDE editor.
When you compile and execute the above program, it will display the following output:
Literal is a constant, which we can directly enter in a program. There are two types of literals as given below:
Alphanumeric Literals are enclosed in an apostrophe. Length can be up to 160 characters. The beginning and ending of a literal should be the same, either quote or apostrophe.
It is a combination of numeric digits from 0 to 9, +, -, or decimal point. Length can be up to 18 characters.
+, - sign cannot be the rightmost character. And decimal point (.) should not appear at the end.
COBOL word is a character string that can be a user-defined word or a reserved word.
User-defined words are used to give a name to a file, data, records, paragraphs, and sections. Digits, alphabets, and hyphens are allowed while forming user-defined words. You cannot use COBOL reserved words.
In COBOL, reserved words are predefined words. Some common reserved words are:
Keywords - e.g., ADD, MOVE, ACCEPT, etc.
Special Characters - e.g., +, - *, <, <=, etc.
Figurative Constants - these are the constant values like ZERO, SPACES, etc. Some Figurative Constants are HIGH VALUES, LOW VALUES, ZERO, SPACES, QUOTES, All literals.