Custom Search

mainframes cobol Interview questions,a cobol programming portal with references from mainframe

Q&A FOR COBOL PROGRAMING

Q Are there other limits on variable names?

A For now, you should ensure that each variable name is different. You have up to 30 characters to use for a variable name, so you should have no trouble coming up with different names.

Q When should you use a variable, and when should you use a constant?

A Most of the work in programming is done with variables. You can use a constant inside the
PROCEDURE DIVISION when it will never need to be changed.

Even when a constant will never change, it sometimes is clearer to use a variable, because it explains what is happening. In the following example, the first line indicates that the sales amount is being multiplied by the constant
.10 (10 percent), but gives no information on why. The value .10 is a constant because it cannot be changed without first editing the program and recompiling it. The second version indicates that some logic is being executed to calculate a sales commission:

MULTIPLY SALES-AMOUNT BY .10.

MULTIPLY SALES-AMOUNT BY COMMISSION-RATE.

Workshop

Quiz

1. How many bytes of memory are used by the following variable?

01 CUSTOMER-NAME PIC X(30).

2. What type of data can be stored in CUSTOMER-NAME?

3. If you move a value to
CUSTOMER-NAME, such as

MOVE "ABC Company" TO CUSTOMER-NAME.

only the first 11 characters of the variable are filled with the value. What is placed in the remaining 19 character positions?

4. What is the largest number that can be moved using
MOVE to the following variable?

01 UNITS-SOLD PIC 9(4).

5. What is the smallest value that can be moved using MOVE to UNITS-SOLD?

6. If
12 is moved to UNITS-SOLD, as in

MOVE 12 to UNITS-SOLD.

what values are stored in the four numeric positions of UNITS-SOLD?

Exercises

1. Modify add02.cbl from Listing 2.5 to display a message that tells the user what the program will do.

Hint: Add a message at line
001500.

2. Pick a poem or phrase of your own choosing that has four or more lines (but no more than 10 lines) and display it on the screen with line numbers.

3. Repeat this poem but have the line numbers start at
05 and increment by 5.

Hint: You can start by moving
5 to THE-NUMBER, and then increment the value by using ADD 5 TO THE-NUMBER for each line that is being printed.