I have confusion regarding COBOL data types. Like in many interviews it is asked to explain the difference between COMP-3 and COMP... what is the exact difference? what is the meaning of usage modes in COBOL and how is it related to data types?
USAGE
in COBOL describes how a data item is to be used. A few examples
of USAGE are:
PIC 9(5) USAGE DISPLAY
describes a 5 digit number that may be displayed (printed).
Often USAGE DISPLAY
is left off because it is implied if missing.There are various types of numeric item. Two of the most commonly used numeric data types are:
COMP (BINARY) data items are generally the most efficient way to perform calculations on data items that represent integer values.
COMP-3 (PACKED-DECIMAL) data items are used in COBOL because they maintain a fixed number of decimal points. All computations lead to a result having the prescribed number of decimal points. This is particularly useful in accounting type operations. Floating point numbers make the number of digits after the decimal point variable (e.g. the decimal point can "float") which is not the way financial operations are usually represented.
You can find a complete list of COMPutational items for IBM Enterprise COBOL here
One of the problems many programmers have when beginning with COBOL is understanding that a COMP item is great for doing math but cannot be displayed (printed) until it is converted into a DISPLAYable item through a MOVE statement. If you MOVE a COMP item into a report or onto a screen it will not present very well. It needs to be moved into a DISPLAY item first.
The other thing that you may want to research a bit more is the relationship between the PICture and the USAGE when defining variables in COBOL. Here is a link to a very good introductory COBOL Tutorial from the University of Limerick.