Data Item Interview Questions
What is a variable or data item?
A variable is a name used to hold the value for processing in the program. It is also called as a data item.
What are the three specific things needed to define a data name or variable in COBOL?
Level number, variable name and PIC clause
How would you declare variables in COBOL?
For Example - Declaring a variable of numeric type to store a value 123.
01 WS-NUMERIC-VAR PIC 9(03) VALUE 123.
- level-number - Refers the level number. From the example, it is 01.
- variable-name - Refers the name of the variable. From the example, it is WS-NUMERIC-VAR.
- data-type-character - Refers the type of the variable. From the example, it is numeric(9).
- variable-length - Refers the variable length. From the example, it is 03.
- literal-value - Refers the initial value assigned to the variable. From the example, it is 123.
What are the three variables used in the presentation?
The variables are divided into three types based on their declaration and those are -
- Individual variable
- Group variable
- Elementary variable
How do you declare VARCHAR(25) In COBOL?
01 WS-VAR PIC X(25).
What is the maximum number of characters that can be used in variable names in COBOL?
30
What are the invalid variable names in the following list - WS-A, VAR, A12, 1A2, WS-
WS-
Specify some variable naming rules?
- The variable name is a combination of COBOL user-defined words that are formed by alphabets(A-Z), digits(0-9) and hyphens (-).
- Variable name length can be a minimum of 1 character and a maximum of 30 characters.
- Variable name should not be a COBOL reserved word(i.e., ACCEPT, ADD, MOVE, etc..).
- The variable name does not allow spaces between the words and should combine them with '-'. Starting or ending character should be an alphabet(A-Z) or a digit(0-9) but not a hyphen(-) or space.
Frequently Asked Questions -
How do you define variables in COBOL?
What is the difference between Global and External Variables?
Not Applicable in z/OS mainframe COBOL.