Coding Sheet in COBOL
Every language needs an environment or platform to write codes. For example, in Java, we use notepad to write codes then compile them to run. Similarly, COBOL requires a coding sheet to write codes. COBOL is a business-oriented high-level language. It was developed for business, finance, and administrative systems for companies and governments. COBOL made data processing easier and is a portable programming language. The full form of COBOL is COmmon, Business-Oriented Language. COBOL code statements are self-explanatory that even a layman would understand. However, it is a hated language but yet surviving. The reason for the survival of this language is that it is still used by the government, banks, and business organizations.
As said earlier, COBOL code statements are self-explanatory but it is difficult to get started with. It is so because the COBOL coding sheet is rigid. A COBOL coding sheet is the COBOL coding structure. The coding sheet is divided into 80 columns. And each column or a particular set of columns are reserved for a particular type of field.
The following table displays what column is reserved for what kind of field:
Column Field 1-3 Page Number 4-6 Line Number 7 Comments/Continuation 8-11 A-Margin / Area A 12-72 B-Margin / Area B 73-80 Identification
- Columns 1-6 are collectively called sequence numbers. The content of sequence number can be any computer character.
- 1-3 columns are reserved for page numbers which automatically gets increased along with the lines of getting added to the program.
- 4-6 columns are reserved for the line numbers. Line number increases with the number of lines of codes in the program.
- The use of the sequence number is optional and can be omitted. However, when sequence numbers are provided they must appear in ascending order.
- This column is reserved for comments. Comment lines are actually some notes which reveal the intentions of the programmer.
- Comment lines can appear anywhere after the first line of the COBOL program.
- If the comment line begins with an asterisk(*) then the comment is not compiled to produce object code. Since they get ignored by the compiler, therefore, anything can be included as comments.
- However, if you begin your comment line with a character slash( / ) then that particular comment line gets printed after causing a page ejection (i.e., after skipping to the top of the next page).
Note: If needed, a statement of cobol program can be written in one or more coding lines. To continue in the next line the coder will have to use a hyphen (-) in column 7.
- Entries in these columns can be started from columns 8,9,10 or 11. Entries of this column are known as Margin-A entries.
- These columns are also known as Area-A.
- All the DIVISION headers, SECTION headers, PARAGRAPH headers, and PARAGRAPH names should start in Area-A.
- The coding of level number 01, as well as that of 77, should start in Area-A.
- Entries in these columns can be started anywhere from columns 12 to 72. Entries of these columns are known as Margin-B entries.
- These columns are also known as Area-B.
- All other statements apart from above i.e. all entries, sentences, and statements should start in Area-A.
- Clauses should be coded in Area-A.
1. Level numbers 02 to 49 can begin in either Area-A or Area-B and should be followed by a space or separator period.
2. Level numbers 66 and 88 can begin either in Area-A or Area-B and must be followed by space.
- These columns are used to write some identification. These are system-generated numbers.
- Everything written in 73-80 columns is ignored by the compiler.
- However, if a printed copy of the program is provided then the entries present in these columns get listed.
The above picture contains a program written in the COBOL coding sheet. All the entries have been made according to the column rules stated above. Sequence numbers aren’t compulsory to write but you must follow the column entry rules.
Whenever we learn any new language, we first learn the alphabet. The alphabets of the COBOL language are known as character set in general. There are in total 50 different characters in the COBOL character set. They are listed as: Arithmetic operator Continuation character Arithmetic operator Comment character Arithmetic operator Comment character Arithmetic operator Relational character Punctuation mark Editing character Punctuation mark Editing character
Character Meaning Usage 0-9 10 numerals Numeric characters A-Z 26 English alphabets- only uppercase letters Alphabetic characters – minus sign or hyphen + plus sign Arithmetic operator * asterisk / slash = equal sign $ currency sign Editing character , comma ; semicolon Punctuation mark . period or decimal point “ quotation mark Punctuation mark ( left parenthesis Punctuation mark ) right parenthesis Punctuation mark < less than symbol Relational character > greater than symbol Relational character
A COBOL character string is a set of adjacent characters that can form a COBOL word, a PICTURE character-string, or a comment.
- COBOL Word: A COBOL word can be formed using alphabetic characters, numeric characters, and hyphens. Following rules must be followed while forming COBOL words:
- A COBOL word can not begin or end with a hyphen.
- A COBOL word can have a maximum of 30 characters.
- One of the characters in a COBOL word must be a letter. According to some COBOL compilers, there is an additional restriction that the first character of the COBOL word must be a letter.
- No special character other than a hyphen is allowed when forming a COBOL word.
There are two types of words in COBOL, they are user-defined and reserved words:
1. COBOL User-defined word: Data names and identifiers are the user-defined Cobol words. A data-name gives reference to the storage space in the memory where the actual value is stored. Data names are only one form of identifier. A data-name cannot be a reserved word.
User-defined words(valid) Invalid user-defined words WS-VAR COMPUTE(Reserved word) NET-SALARY ADD(Reserved word) MARK1 MULTIPLY(Reserved word)
In the above program, XX defined at level 01 is a user-defined word representing a group item named XX that contains table B.
NOTE: Arrays in COBOL are known as tables.
2. Reserved word: Reserved words in COBOL have a specific purpose.
Reserved word Purpose ADD Used to perform addition COMPUTE Used when mathematical formulas are to be dealt ACCEPT Used to store input in data names
The above program explains the functioning of reserved words given in examples. There are many reserved words other than the three stated and explained above.
NOTE: Whenever you need to write equation in cobol then you must include whitespace between the operator and operand.
- Literals: A literal in COBOL is often called a constant as its value remains unchanged throughout the execution of the program. There are three types of literals, namely: numeric, non-numeric, and figurative constants.
1. Numeric: Numeric literals are formed with the help of digits. It can have a + sign or a – sign and can have a decimal point too. For a numeric literal to be positive there’s no need to specify the sign, however, if you want the literal to be negative, a – sign should be specified at the leftmost end. The decimal point in literals helps to identify whether the number is floating-point or integer. The maximum number of digits allowed in numeric literal is compiler dependent.
Valid numeric literal Invalid numeric literal .456 “789” 85.6 – 56
2. Nonnumeric: This type of literal is used as output messages or headings. A non-numeric literal is enclosed between two quotation marks. The number of characters that can be enclosed between the two quotation marks is compiler-dependent.
Valid nonnumeric literal Invalid non-numeric literal “DATA DIVISION” 8 “SPEED/HOUR” “SEVEN “56.6” 45.3″
3. Figurative Constants: These are the reserved words that refer to specific constant values.
For example: Consider the statement: MOVE ZERO TO A. Here the value 0 will be moved to the data name A. The word ZERO is a figurative constant having a value of 0. Some other examples of figurative constants are: ZEROS ZEROES SPACE SPACES HIGH-VALUE HIGH-VALUES LOW-VALUE LOW-VALUES QUOTE QUOTES
Figurative Constant Meaning has value 0 one or more blank The highest value in the collating sequence The lowest value in the collating sequence one or more of “ ALL literal one or more of the string characters comprising the literal