COBOL - Coding Sheet
Every programming language requires an environment or platform to write codes before compilation and execution. For example, in Java programming language, notepad is used to write programs before compile and run them.
In the same way, we need a platform to write COBOL codes. In COBOL programming language, we use a coding sheet to write codes.
In COBOL program structure, the COBOL code statements are self-explanatory that are easy to understand. COBOL is a high-level business-oriented programming language. It is mainly used for business, finance, and administrative systems for companies and governments. When the COBOL was created, the COBOL programs are required to punch on the card, and it then loaded to punch card readers. Nowadays, COBOL uses some new editors instead of punched cards, but the same coding sheet is used to write the codes.
The COBOL code statements are self-explanatory but using a COBOL coding sheet is not a easy task. A COBOL coding sheet is the COBOL coding structure and is divided into 80 columns. Each column or a particular set of columns are reserved for a particular type of field.
In short, we can say that we have to write the COBOL source program in a specific format that should be accepted by the COBOL compilers. That's why we should always write COBOL programs on COBOL Coding Sheet.
The COBOL Coding Sheet has 80 character positions and these positions are grouped into the following five fields:
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 component in the COBOL hierarchy structure, and they cannot be further divided. The following table specifies all the COBOL characters used in COBOL Character Set:
A character string is a collection of individual characters. A character string can be a:
A comment is a written statement which is used to specify the programmers' remark in the source code. The content written as the comment is ignored by the compiler.
Generally, the programmers write down some comment lines to make the code easily understandable by other users or programmers. Comment lines can appear anywhere after the first line of the COBOL program.
Following are the two types of comments used in COBOL codes:
We can write the comment line in any column. The compiler does not check a comment line for syntax and use it for documentation.
If the comment line starts with an asterisk (*), then the comment is not compiled to produce object code. It is completely ignored by the compiler. On the other hand, if the comment line starts with a character slash (/), then that particular comment line gets printed and the page is ejected.
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.