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:
|1-6||Columns Numbers||The column numbers 1-6 are collectively called sequence numbers. These are used for the line number for counting lines of code. The content of sequence number can be any computer character. It is optional to use and can be omitted. But if the sequence numbers are provided, they must appear in ascending order.|
|7||Indicator||This column is used as an indicator and is reserved for comments. It can have (*, -, /). Asterisk (*) is used for comments, Hyphen (-) indicates continuation, slash (/) indicate form feed. 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.|
|8-11||Area A||These columns are also called Area-A. In these columns, entries can be started from columns 8, 9, 10 or 11. Entries of this column are called Margin-A entries. All COBOL divisions, paragraphs, sections, and some special entries must begin in Area A.|
|12-72||Area B||These columns are also called Area-B. In these columns, entries can be started from columns 12 to 72. Entries of this column are called Margin-B entries. All COBOL statements must begin in Area B.|
|73-80||Identification Area||These columns are used for the identification of each line in the code. The programmers can use it as per their needs.|
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:
|1.||A-Z||Alphabets (Upper Case)|
|2.||a-z||Alphabets (Lower Case)|
|6.||–||Minus Sign or Hyphen|
|9.||$||Currency (Dollar) Sign|
|12.||.||Decimal point or period|
A character string is a collection of individual characters. A character string can be a:
- COBOL Word
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 valid’||‘It is not valid”|
|“It is valid”||“It is not valid’|
|‘It doesn’ ‘t invalid’||‘It doesn’t valid’|
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.