Basic Verbs


Every programming language is designed with some system-defined set of characters, symbols, keywords, and standards. Similarly, COBOL has its own set of characters, symbols, keywords, and standards. Below are the basic and known terms in the COBOL –

  • Character set
  • Character strings
    • COBOL Words
    • Variables
    • Literals
    • Constants
    • Figurative Constants
    • Comments
  • Separators

Character set


The character set refers to the collection of valid characters that can be used within the language. These are used to define literals, variables, and other identifiers in a COBOL program.

The COBOL language has its own set of valid characters (78) that contains alphabets (A-Z | a-z), digits (0-9), and special characters. The list of basic COBOL characters are –

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

Character Strings


The character string is a set of characters created for a purpose or to name something. Character strings are used as -

  • COBOL Words
  • Variables
  • Literals
  • Constants
  • Figurative Constants
  • Comments

COBOL Words


A COBOL word is a set of characters, and each character is from the character set - A to Z, 0 to 9, - (hyphen), _ (underscore). COBOL word minimum length is 1 character and maximum length is 30 characters.

COBOL Word Types -

COBOL words are two types and those are -

  • User-defined Words - Any word coded by the developer in the program is considered as a user-defined word. For Example - MTHPROG1, STD-GENDER, ....
  • Reserved Words - A reserved word is a system-defined word with proper meaning or task assigned in COBOL language. For Example - ACCEPT, SKIP1, ZEROS, ....

Variable


A Variable is a data name used to hold the value for processing in the program. A Variable is also called as a data item. For Example - WS-A, WS-VAR, WS-TOTAL, WS-INPUT, WS_OUTPUT, etc. Every variable should declare in the DATA DIVISION of the COBOL program.

We will learn more about variable in the further topics.

Literal


The literal is the value that is assigned to the variable. The value can be a string or number or a figurative constant. Literals are classified into two types –

  • Non-numeric literals - Non-numeric literals are the strings enclosed by quotation marks(") or apostrophes('). It can contain all valid character that are allowed by COBOL.
    For Example - "HELLO", "THIS ISN'T WRONG", etc.
  • Numeric literals - A numeric literal is a number that is a combination of a sign character (+ or -), and a decimal point. A numeric literal codes directly without quotation marks(" ") or apostrophes(' ').
    For Example - 1234, -1234, etc.

Constant


A variable can be initialized with a literal. If the literal doesn't change during the program's execution, the variable is considered as a constant variable, and the value is considered as a constant value.

Constants are three types, and those are –

  • Numeric constants – Numeric variables having one value throughout the program execution are called numeric constants. For example - 01 WS-PI PIC 9(2)V9(2) VALUE 3.14.
  • Alphanumeric | non-numeric constants – Alphanumeric variables that have only one value throughout the program execution are called as alphanumeric constants. For example - 01 WS-HI PIC X(05) VALUE "HI".
  • Figurative Constants - System-defined constants are predefined in the COBOL and used as replacement for standard values like spaces, zeroes, etc. For example - 01 WS-VAR PIC 9(5) VALUE ZEROES.

Figurative Constant -

Figurative constants are system-defined keywords with predefined values. The figurative constants in COBOL are -

Figurative constant Description
ZERO,
ZEROS,
ZEROES
Represents one or more occurrences of the numeric value 0. ZERO is a single 0 and ZEROS or ZEROES means two or more occurrences of 0s.
SPACE,
SPACES
Represents one or more occurrences of the space. i.e., " " or X'40'. SPACE is single SPACE (" "), and SPACES means two or more occurrences of space.
HIGH-VALUE,
HIGH-VALUES
Represents one or more occurrences of the high-value. i.e., X'FF'.
LOW-VALUE,
LOW-VALUES
Represents one or more occurrences of the low-value. i.e., X'00').
QUOTE,
QUOTES
Represents one or more occurrences of quotation mark (") or apostrophe (').
ALL Represents one or more occurrences of the characters string or figurative constant.

Comments


A comment is dummy statement that is used to provide information about code or requirements. All computer-supported characters are allowed to write a comment and it do not affect the execution of the program.

The comments are considered as three types based on their usage and where they are used -

  • IDENTIFICATION DIVISION Comments - The entries with optional paragraphs are comments and their usage is -
           AUTHOR. NameOfProgrammer.
           INSTALLATION. Development-center.
           DATE-WRITTEN. mm/dd/yy.
           DATE-COMPILED. mm/dd/yy. HH:MM:SS.
           SECURITY. Program-type.
  • Full line comments (any division) - Any line starting with an asterisk (*) in column 7 (indicator area) is considered as a full-line comment. For example -
    ----+----1----+----2----+----3----+----4----+----5
          * FULL LINE COMMENT WITH * IN COLUMN-7.
  • An inline comment starts with a floating comment indicator (*>) in the middle of any line in between 8-72 columns. For example -
           01 WS-VAR        PIC X(12).    *> INLINE COMMENT   

Separators


A separator is a single or multiple character that separates words or strings. The below table shows the separators list -

SeparatorMeaningSeparatorMeaning
Space:Colon
,Comma"Quotation mark
.Period'Apostrophe
;Semicolon==Pseudo-text delimiter

Practical Example -


Scenario - Below screenshot describes the different types of character strings in COBOL programming.

Character String Code example