sign in
 
   
 
 
 
   
  COBOL TUTORIAL FOR BCA STUDENTS OF M G UNIVERSITY  
  UNIT 3: INTRODUCTION TO COBOL . . .  
   
  COBOL WORDS  
     
 

A COBOL word can be formed using the following characters:

0-9
A-Z (a-z)
- (hyphen)

The following rules must be adhered in forming COBOL words:

A word cannot begin or end with a hyphen. A word can have at the maximum 30 characters. One of the characters must be a letter. Some compilers put the additional restrictions that the first character must be a letter. Except hyphen (-) no special character allowed.


Examples
Valid Cobol Word :
EMP-SAL
NET-SALARY
TOT-MARK
N100

Invalid Cobol Word :
-PAY (it starts with a hyphen)
TOTAL MARK (blank space embedded)
COMPUTE (Reserved word)
MULTIPLY (Reserved word)
23 (No letter)

There are 2 types of words in COBOL. A COBOL word can be either a USER-DEFIND WORD or RESERVED WORD. The reserved words are used in COBOL statements and entries for specific purposes by the COBOL compiler.

Some reserved words are given below:
ADD, SUBTRACT, DIVIDE, MULTIPLY, IF, PERFORM etc.

Any attempt by the programmer to declare the reserved word will be indicated as an error during the compilation stage of the program.

 
   
  DATA NAMES AND IDENTIFIERS  
     
 
A DATA NAME gives reference to the storage space in the memory where the actual value is stored. This value takes part in the operation when that particular data name is used in the PROCEDURE DIVISION.

IDENTIFIER is a general term which means the single data name or a data name qualified, indexed or subscripted. Data names are only one form of identifiers. A data name must be a user-defined word and it cannot be a reserved word.

 
   
  LITERALS  
 

The actual values can also appear in a program. Such values are known as literals. For Example, the statement MOVE 0 TO TOTAL indicates that the value zero will be moved to the variable TOTAL. This constant 0 which used in the body of the statement is a literal.

A data name may have different values at different points of time whereas a literal means the specific value which remains unchanged throughout the execution of the program. For this reason a literal is often called a constant. Moreover the literal is not given a name; it represents itself and does not require to be defined in the DATA DIVISION.

There are 3 types of literals:

a) Numeric Literals
b) Nonnumeric Literals
c) Figurative constants

 
 

NUMERIC LITERALS

 
 

A numeric literal can be formed with the help of digits only. It can have a sign (+ or -) and can have a decimal point also. If no sign is specified the literal will be taken as positive. Negative literals are indicated by – sign at the leftmost end. If no decimal point is used then the literal is obviously an Integer. If a decimal point is used, it must come in between the digits. The maximum number of digits allowed in a numeric literal is compiler dependent.

 
 
Example: .125, 12.5

 
  NON-NUMERIC LITERALS  
 

A nonnumeric literal is used in general to output messages or headings. Characters that are enclosed between “ “ constitute nonnumeric literal. The maximum number of characters that are allowed within two quotation marks is compiler dependent.

 
  Examples:

“M G UNIVERSITY”
“DATA DIVISION”
“250.50”
“METER/SECOND”


 
  FIGURATIVE CONSTANTS  
 

Figurative constants have some fixed names and the compiler recognizes these names and it sets up corresponding values in the object program. Consider the statement given below :

MOVE ZERO TO COUNTER

Here value 0 will be moved to COUNTER by the compiler, as it recognizes ZERO and sets COUNTER with 0.

Given below is the list of figurative constants:

 
 
Figurative Constant

Meaning
ZERO Value 0
ZEROS
ZEROES
   
SPACE One or more blanks
SPACES
   
HIGH-VALUE Highest value in the Collating sequence
HIGH-VALUES
   
LOW-VALUE Lowest value in the Collating sequence
LOW-VALUES
   
QUOTE One or more of “
QUOTES
   
ALL Literal One or more of the string characters comprising the literal