Words


A COBOL word is a set of characters, and each character is from the following character set -

  • Latin uppercase letters A through Z
  • Latin lowercase letters a through z
  • digits 0 through 9
  • - (hyphen)
  • _ (underscore)

COBOL word minimum length is one character, and the maximum is 30 characters.

Rules -

  • Each lowercase alphabet is equivalent to its uppercase.
  • The hyphen(-) or underscore(_) cannot appear as the first or last character.

COBOL word types -


COBOL words are two types and those are -

  • User-defined Words.
  • Reserved Words.

User-defined words -


  • Any word coded by the developer in the program is considered as a user-defined word.
  • These user-defined word process the data or name a paragraph, section, etc.

Rules -

  • The user-defined word should be unique within its type where it belongs to (a section, paragraph, group variable, etc.).
  • All user-defined words should contain at least one alphabetic character (except section names, paragraph names, and level numbers).

Examples -

The below list shows the different user-defined names and examples of their usage in the program -

User-defined name Some Examples
Variable name
05 STD-GENDER PIC A(06).
STD-GENDER is a variable name.
Condition name
05 STD-GENDER PIC A(06).
   88 STD-MALE VALUE "MALE".
   88 STD-FEMALE VALUE "FEMALE".
STD-MALE, STD-FEMALE are the condition-names.
Constant name
01 WS-PI      PIC 9.99 VALUE 3.14.
WS-PI is the constant name.
File name
FILE-CONTROL.
	SELECT INPUT-FILE ASSIGN TO DISK01.
INPUT-FILE is the file name.
Index name
01 BTECH-1ST-YEAR.
    03 SUBJECT-MARKS    PIC 9(03) OCCURES 6 TIMES
				INDEXED BY MARKS-INDEX.
MARKS-INDEX is the index name.
Mnemonic name
SPECIAL-NAMES.
    SRW IS SORT-SWITCH ON STATUS IS SORT-ON.
SRW is the mnemonic name.
Paragraph name
	PERFORM PARA-DISPLAY 10 TIMES.
	.
	.
PARA-DISPLAY.
	.
PARA-DISPLAY is the paragraph name.
Program name
PROGRAM-ID. MTHPROG1.
MTHPROG1 is the program name.
Record name
01 WS-REC.
	05 WS-REC-KEY PIC X(10).
	05 FIELD1     PIC X(10).
	.
	.
WS-REC is the record name.
Section name
SEC-ADDITION SECTION.
SEC-ADDITION is the section name.
Symbolic character
SYMBOLIC CHARACTERS BACKSPACE IS 23.
BACKSPACE is the symbolic character.

Reserved words -


A reserved word is a system-defined word with proper meaning or task assigned in COBOL language. Reserved words can be -

  • Keywords.
  • Optional Words.
  • Figurative Constants.
  • Special Character Words.
Reserved WordDescription
Keywords The keyword is a system-defined word with a definition and usage to perform the assigned task via coding.

For Example -
ACCEPT
ADD
ALPHABET
AUTHOR 
...
Optional words Optional words are system-defined words that do not affect the program's execution.
They add to a sentence or statement to improve readability.

For Example -
SKIP1
SKIP2
SKIP3
...
Figurative constants The figurative constant is a system-defined word assigned with a constant value.

For Example -
ZEROS, ZEROES
SPACE, SPACES
HIGH-VALUE, HIGH-VALUES
...
Special character words Special character words are system-defined characters assigned to complete an operation. There are five types of special character words -

  • Arithmetic operators: + - / * **
    For Example -
    COMPUTE WS-SUM = WS-A + WS-B.
    COMPUTE WS-SUB = WS-A - WS-B. 
    COMPUTE WS-DIV = WS-A / WS-B.
    COMPUTE WS-MUL = WS-A * WS-B. 
    COMPUTE WS-EXP = WS-A ** WS-B. 
  • Relational operators: < > = <= >=
    For Example -
    IF WS-A < WS-B 
    IF WS-A > WS-B
    IF WS-A = WS-B
    IF WS-A <= WS-B
    IF WS-A >= WS-B 
  • Floating comment indicators: *>
  • Pseudo-text delimiters in COPY and REPLACE statements: ==
    For Example -
    COPY COPYBOOK REPLACING ==:WS:== BY ==WS1==.
  • Compiler directive indicators: >>