What is the COBOL word?

A COBOL word is a set of characters that are written continuously (side by side). Each character of a COBOL word is from the following set -

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

COBOL word can have a length from 1 to 30 characters.

Rules

Programmer should follow the below guidelines while creating COBOL words -

  • Each lowercase alphabetic letter is equivalent to its uppercase alphabetic letter.
    For example -
    "a" is equal to "A".
  • The hyphen(-) or underscore(_) cannot appear as the first or last character.
    For example -
    -WS
    WS-
    _WS
    WS_ 	are invalid.
  • All user-defined words must contain at least one alphabetic character (except section-names, paragraph-names, and level-numbers).
    For example -
    A123
    W-12
    1W2
    12W etc,.		are valid
  • A reserved word cannot use as a user-defined word or a system-name.
    For example -
    ZERO
    MOVE
    IF
    ELSE etc, 	are invalid as user-defined words.
  • The same COBOL word can use as a user-defined word or a system name, or both depending on the context.

COBOL word types -

COBOL words are 5 types and those are -

COBOL word type Description
User-defined words A user-defined word is defined by the developer and used to store the data.

The user-defined word maximum length is 30 bytes (except for level-numbers).
System-names A system name is a character string that is assigned to a system as a name in the mainframe environment.
There are three types of system-names -
  • Computer name
  • Language name
  • Implementor name

For example -
Type Some Examples
Computer Name
SOURCE-COMPUTER. Alpha.
OBJECT-COMPUTER. Beta.
Language Name
INSTALLATION. COBOL DEVELOPMENT CENTER.
Implementor Name
AUTHOR. PROGRAMMER NAME(MTH).
Function-names A function name specifies the name to define an intrinsic function.
The same word can appear in a program as a user-defined word or a system-name in a different context.
For example -
CHAR
LENGTH
MIN
MAX
SQRT
...
Context-sensitive words A context-sensitive word is created according to rules for reserved words and may be used as a function-name, a user-defined word, or a system name.
For example -
APPEND
DAYS
DEFAULT
HOURS
MICROSECONDS
MINUTES
MONTHS
SECONDS
SYMMBOL
TIMSTAMP
YEARS
YYYYDDD
YYYYMMDD
...
Reserved words A reserved word is a predefined word in a COBOL language with proper meaning.

Reserved words can be Keywords, Optional words, Figurative constants, Special character words and Special registers.

User-defined words -

  • The developer defines a user-defined word and is used to store the data.
  • The user-defined word maximum length is 30 bytes (except for level-numbers).

Rules -

  • The user-defined word should be unique within the type to which it belongs (that might be a program, paragraph, etc.).
    Example -
    01 WS-VAR1 PIC X(05).
    WS-VAR1 should be unique variable in the program where it is declared.
  • 01-PARA1.
    01-PARA1 should be unique paragraph in the program where it is declared.
  • User-defined word can be duplicated. The reference should be used with condition-names, data-names, record-names and paragraph-names.
    Example -
    01 WS-GRP1.
    	05 WS-VAR1 PIC X(05).
    01 WS-GRP-BACKUP.
    	05 WS-VAR1 PIC X(05).
    The above declaration is valid as it has a reference and should be represented as -
    WS-VAR1 OF WS-GRP1
    WS-VAR1 OF WS-GRP-BACKUP
    In the above case, the two usages consider as two different variables.

Rules Specific to the user-defined name types-

The below list specifies some types of user-defined names –

Rules User-defined name types
Each word atleast have one letter. Alphabet-name
Condition-name
Constant-name
Data-item-name
File-name
Index-name
Mnemonic-name
Program-name (Using in PROCEDURE linkage)
Record-name
Routine-name
Each word atleast have one letter.
First 10 character should be unique word.
Library-name
Program-name(using PROGRAM linkage)
Text-name
Word may need not contain alphabetic character. Paragraph-name
Section-name
Each word may contain 1 or 2 digits.
It does not have to be unique.
Level-numbers

Example -

The below list shows the examples for each type of user-defined name -

User-defined name Some Examples
Alphabet-name
SPECIAL-NAMES. 
    ALPHABET SORT-SEQ IS "A" THROUGH "Z"
                         "a" THROUGH "z".
SORT-SEQ is the alphabet-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.
Data-item-name
05 WS-VAR     PIC X(05).
WS-VAR is the data-item-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.
Routine-name
CALL ROUTINE1 USING variable-1, variable-2.
ROUTINE1 is the routine-name.
Section-name
SEC-ADDITION SECTION.
SEC-ADDITION is the section-name.
Key-name
FILE-CONTROL.
	SELECT INPUT-FILE ASSIGN TO DISK01.
		.
		.
	RECORD KEY IS WS-REC-KEY.

	01 WS-REC.
		05 WS-REC-KEY PIC X(10).
		05 FIELD1     PIC X(10).
		.
		.
WS-REC-KEY is the key-name.
Symbolic-character
SYMBOLIC CHARACTERS BACKSPACE IS 23.
BACKSPACE is the symbolic-character.
Text-name
05 WS-MTH PIC X(20) VALUE "MAINFRAMESTECHHELP".
WS-MTH is the text-name.

Reserved words -

A reserved word is a predefined word in a COBOL language with proper meaning. Reserved words can be -

  • Keywords
  • Optional words
  • Figurative constants
  • Special character words
  • Special registers
Reserved WordDescription
Keywords Keywords are reserved words that are required to code each program.
Such keywords appear in uppercase on each sentence or statement.
For example -
ACCEPT
ACCESS
ADD
AFTER
ALL
ALPHABET
ALPHABETIC
ALPHANUMERIC
ASCENDING
ASSIGN
AUTHOR 
...
Optional words Optional words are reserved words that do not affect the program's execution.
They can be included in a sentence or statement to improve readability.
For example -
SKIP1
SKIP2
SKIP3
ROUNDED
...
Figurative constants Figurative constants are reserved words and refers to specific constant values.
For example -
ZERO, ZEROS, ZEROES
SPACE, SPACES
HIGH-VALUE, HIGH-VALUES
LOW-VALUE, LOW-VALUES
QUOTE, QUOTES
NULL, NULLS
...
Special character words Special character words are used for a special purpose.
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: >>
Special registers Special registers represent storage areas generated by the compiler.
Their primary use is to store information produced by specific COBOL components.
Each storage area has a fixed name and should not be defined within the program.
For example -
ADDRESS OF
DEBUG-ITEM
FORMAT OF
LENGTH OF
LINAGE-COUNTER
RETURN-CODE
SORT-RETURN
WHEN-COMPILED
...