COBOL 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 |
STD-GENDER is a variable name. |
| Condition name |
STD-MALE, STD-FEMALE are the condition-names. |
| Constant name |
WS-PI is the constant 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. |
| Section name |
SEC-ADDITION is the section name. |
| Symbolic character |
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 Word | Description |
|---|---|
| Keywords | The keyword is a system-defined word with a definition and usage to perform the assigned task via coding. For Example -
|
| 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 -
|
| Figurative constants | The figurative constant is a system-defined word assigned with a constant value. For Example -
|
| Special character words | Special character words are system-defined characters assigned to complete an operation. There are five types of special character words -
|