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 |
1-6 columns:
- 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.
Column 7:
- 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.
8-11 columns:
- 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.
12-72 columns:
- 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.
Note:
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.
73-80 columns:
- 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.
Example:
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.
Character Set:
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:
Character | Meaning | Usage |
---|
0-9 | 10 numerals | Numeric characters |
A-Z | 26 English alphabets- only uppercase letters | Alphabetic characters |
- | minus sign or hyphen |
Arithmetic operator
Continuation character
|
+ | plus sign | Arithmetic operator |
* | asterisk |
Arithmetic operator
Comment character
|
/ | slash |
Arithmetic operator
Comment character
|
= | equal sign |
Arithmetic operator
Relational character
|
$ | currency sign | Editing character |
, | comma |
Punctuation mark
Editing character
|
; | semicolon | Punctuation mark |
. | period or decimal point |
Punctuation mark
Editing character
|
" | quotation mark | Punctuation mark |
( | left parenthesis | Punctuation mark |
) | right parenthesis | Punctuation mark |
< | less than symbol | Relational character |
> | greater than symbol | Relational character |
Character strings:
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) |
Example:
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.
For example:
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 |
Example:
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:
Figurative Constant | Meaning |
---|
ZEROS
ZEROES
| has value 0 |
SPACE
SPACES
| one or more blank |
HIGH-VALUE
HIGH-VALUES
| The highest value in the collating sequence |
LOW-VALUE
LOW-VALUES
| The lowest value in the collating sequence |
QUOTE
QUOTES
| one or more of " |
ALL literal | one or more of the string characters comprising the literal |
Similar Reads
Conditional Statements in COBOL
While writing a program a programmer needs to check for various conditions, if the condition is true then a particular block of statement/s are executed, or else another block of statement/s is execute. To check these conditions we use Conditional Statements. These statements return either true or f
7 min read
String Handling in COBOL
The string is the data type, used to represent the sequence of characters, which ends with /0. String provides much functionality which makes our programming easy when it comes to groups of chars, words, sentences, or lines. String Handling:  String handling is the process or method to handle the s
7 min read
COBOL - Continue Statement
In simple terms think of the continue statement as a Gatekeeper who will open the gate for the people to come inside the premise to do their task. Similarly continue statement also transfers the control on the next COBOL statement for execution. Syntax: CONTINUE Let's take the example of Continue in
2 min read
File Section in COBOL
COBOL is a high-level programming language for business applications or business use. It was designed in 1959 by the Conference on Data Systems Language (CODASYL). It was primarily used in business, finance, and administration system for companies and governments. COBOL is still widely used in appli
6 min read
Linkage Section in COBOL
The linkage Section in COBOL is used to declare the variables and it is used in calling the variable from another program. It is used in calling the variable or data from the called program by using the CALL statement. The linkage Section helps in sending the data to the calling program or receivin
4 min read
Next Sentence in COBOL
In COBOL programming language we have three types of logical statements: 1. Sequence Statements: Used when we need to execute some piece of code repeatedly till some sequence. Like reading each data/record from some file till the end. 2. Selection Statements: Used when we want to flow the program ba
3 min read
Internal Sort in COBOL
Internal Sequential files are often used in big data operational processing applications, necessitating the records to be arranged in an operational ascending or descending order. This ensures quick access to the data and makes it easier to retrieve. Furthermore, sorting data in a file or combining
4 min read
COBOL - Copy Statement
COPY statement is used to bring into a program a series of prewritten COBOL entries that have been stored in a library. A copy statement inserts the copybook inside a COBOL program, copybook refers to a member which holds all the variables declared inside it. The COPY statement is a library statemen
2 min read
Loop Statements in COBOL
Every programming language not only has a selection construct but also one that involves iteration. With this construct, it is possible for a block of code to run repeatedly. In fact, the programmer himself can code it in by selecting a specific type of loop. Speaking of types of loops, modern prog
8 min read
COBOL Divisions
COBOL stands for Common Business-Oriented Programming Language, which is one of the oldest and first high-level programming languages. It is mostly used for the defense and insurance domains which require huge data processing. Features of COBOL:It is a business-oriented and robust languageProvide go
4 min read