COBOL - Language Structure
Basic COBOL character set
- The most basic and indivisible unit of the COBOL language is the character.
- The basic character set includes the letters of the Latin alphabet, digits, and special characters.
- In the COBOL language, individual characters are joined to form character-strings and separators.
- Character-strings and separators, then, are used to form the words, literals, phrases, clauses, statements, and sentences that form the language.
|-||Minus sign or hyphen|
|/||Forward slash or solidus|
|.||Decimal point or period|
|A - Z||Alphabet (uppercase)|
|a - z||Alphabet (lowercase)|
|0 - 9||Numeric characters|
A character-string is a character or a sequence of contiguous characters that forms a COBOL word, a literal, a PICTURE character-string, or a comment-entry. A character-string is delimited by separators.
A separator is a character or a string of two or more contiguous characters that delimits character-strings. The separators are shown in the following table. there are many seperator are available. here listed only important seperator.
and many more...
COBOL WordsA COBOL word is a character-string that forms a user-defined word, a system-name, or a reserved word.
- User-defined word - Charater string that has a specific purpose in the program. User-defined words are used for naming files, data, records, paragraph names, and sections. Alphabets, digits, and hyphens are allowed while forming userdefined words. You cannot use COBOL reserved words.
Rules of User-Defines Words
- Max. Length 30 Chars
- Must contain only Digits, Letters and Hyphens
- Must not be a Reserved Word
- Include at least one Letter
- Hyphens are imbedded
- Must not have Spaces
- System-name - A system-name is a character string that has a specific meaning to the system.
- Reserved word - A reserved word is a character-string with a predefined meaning in a COBOL source unit.
There are six types of reserved words:
- Keywords are reserved words that are required within a given clause, entry, or statement. Within each format, such words appear in uppercase on the main path. Keywords like ADD, ACCEPT, MOVE, etc.
- Optional words - Optional words are reserved words that can be included in the format of a clause, entry, or statement in order to improve readability. They have no effect on the execution of the program.
- Special characters words - There are two types of special character words.
- Arithmetic operators: + - / * **
- Relational operators: <>=<=>=
- Figurative constants are reserved words that name and refer to specific constant values like ZERO, SPACES, HIGH-VALUE, LOW-VALUE etc.
- Special object identifiers - COBOL provides two special object identifiers, SELF and SUPER
- Special registers - Special registers are reserved words that name storage areas generated by the compiler. Their primary use is to store information produced through specific COBOL features. Each such storage area has a fixed name, and must not be defined within the program. Example: ADDRESS-OF, RETURN-CODE, SORT-CONTROL, LENGTH OF, WHEN-COMPILED etc..
A literal is a character-string whose value is specified either by the characters of which it is composed or by the use of a figurative constant. Following are the main features of Literals:
Examples of Numeric Literals
- Literals are Constants
- Literals can be Numeric or Non-Numeric
Rules for Numeric Literals
Following rules should be kept in mind while creating numeric literals:
Rules for Non-Numeric Literals
- Contains a minimum of 1 digit and can have maximum of 18 digits
- Sign, if used, must be left-most character and must not be more than one
- Decimal, if used, may not be right-most character and must not be more than one
Following rules should be kept in mind while creating Non-numeric literals
Rules for Floating Point Literals
- Any character in the Character Set allowed
- Must be enclosed in Quotes
- 2 continuous Quotes to get 1 Quote
- Numeric Literal in Quotes is Non-Numeric
- Maximum Length is 160 Characters
Following rules should be kept in mind while floating Point literals:
- Useful for very high or very small values
- Specified as Numeric Literal with decimal point, followed by
- Letter E
- 2-Digit Number
- Must fall between 0.54E-78 and 0.72E+76.
A comment is a character-string that can contain any combination of characters from the character set of the computer. It has no effect on the execution of the program.
A comment line is any line with an asterisk (*) or slash (/) in the indicator area (column 7) of the line. The comment can be written anywhere in Area A and Area B of that line, and can consist of any combination of characters from the character set of the computer.
Comment lines can be placed anywhere in a program, method, or class definition. Comment lines placed before the identification division header must follow any control cards(for example, PROCESS or CBL).
Important: Multiple comment lines are allowed. Each must begin with either an asterisk (*) or a slash (/) in the indicator area(column 7).
If you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on ibmmainframer Community!