TSO-ISPF JCL COBOL VSAM DB2 CICS Tools Articles Job Portal Forum Quiz Interview Q&A

COBOL - Language Structure


  • 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.

Basic COBOL character set

CHARACTERMEANING
Space
+Plus sign
-Minus sign or hyphen
*Asterisk
/Forward slash or solidus
=Equal sign
$Currency sign
,Comma
;Semicolon
.Decimal point or period
"Quotation mark
'Apostrophe
(Left parenthesis
)Right parenthesis
>Greater than
<Less than
:Colon
_Underscore
Alphabet (uppercase)
A - ZAlphabet (uppercase)
a - zAlphabet (lowercase)
0 - 9Numeric characters

Character-strings:
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.

Seperator:
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.

SEPARATORMEANING
Space
,Comma
.Period
;Semicolon
(Left parenthesis
)Right parenthesis
:Colon
and many more...

COBOL Words

A COBOL word is a character-string that forms a user-defined word, a system-name, or a reserved word.
  1. 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

  2. System-name - A system-name is a character string that has a specific meaning to the system.

  3. 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:
    1. 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.

    2. 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.

    3. Special characters words - There are two types of special character words.
      1. Arithmetic operators: + - / * **
      2. Relational operators: <>=<=>=

    4. Figurative constants are reserved words that name and refer to specific constant values like ZERO, SPACES, HIGH-VALUE, LOW-VALUE etc.

    5. Special object identifiers - COBOL provides two special object identifiers, SELF and SUPER

    6. 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..

Literals:

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:
  • Literals are Constants
  • Literals can be Numeric or Non-Numeric
Examples of Numeric Literals

NumericNon-Numeric
123.456TUTORIAL
8881SCHOOL
-111.95
0.45E-87

Rules for Numeric Literals

Following rules should be kept in mind while creating 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
Rules for Non-Numeric Literals

Following rules should be kept in mind while creating Non-numeric 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
Rules for Floating Point Literals

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
  • Sign
  • 2-Digit Number
  • Must fall between 0.54E-78 and 0.72E+76.

Comments:

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!

Are you looking for Job Change? Job Portal