Summary -
In this topic, we have explained about the below sections -
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 -
For example -
|
||||||||
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 -
|
||||||||
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 -
|
||||||||
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 -
WS-VAR1 should be unique variable in the program where it is declared.01 WS-VAR1 PIC X(05).
01-PARA1.
01-PARA1 should be unique paragraph in the program where it is declared.
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 |
SORT-SEQ is the alphabet-name. |
Condition-name |
STD-MALE, STD-FEMALE are the condition-names. |
Constant-name |
WS-PI is the constant-name. |
Data-item-name |
WS-VAR is the data-item-name. |
File-name |
INPUT-FILE is the file-name. |
Index-name |
MARKS-INDEX is the index-name. |
Mnemonic-name |
SRW is the mnemonic-name. |
Paragraph-name |
PARA-DISPLAY is the paragraph-name. |
Program-name |
MTHPROG1 is the program-name. |
Record-name |
WS-REC is the record-name. |
Routine-name |
ROUTINE1 is the routine-name. |
Section-name |
SEC-ADDITION is the section-name. |
Key-name |
WS-REC-KEY is the key-name. |
Symbolic-character |
BACKSPACE is the symbolic-character. |
Text-name |
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 Word | Description |
---|---|
Keywords | Keywords are reserved words that are required to code each program. Such keywords appear in uppercase on each sentence or statement. For example -
|
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 -
|
Figurative constants | Figurative constants are reserved words and refers to specific constant values. For example -
|
Special character words | Special character words are used for a special purpose. There are five types of special character words -
|
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 -
|