Constant Variables and Display
|
The general format of the program now that it contains variables.
Three variables are created in this program: FIRST-NUMBER, SECOND-NUMBER,
and THE-RESULT.
Each variable has the level number 01.
The first two have pictures of 99 and will hold values ranging from 0 through 99. The third variable, THE-RESULT, has a picture of 999 and will hold a value of 0 through 999. Once again, the PICTURE IS clause does not set the value of the variable; it sets only the largest and smallest values that a variable can hold and the fact that the variable will hold numeric data.
When you run the program, you will be asked to enter the first number,
as shown in the following output. Note that the final blank line
003100 in the listing has no effect on the program.
You can leave it out if you wish.
OUTPUT: C>pcobrun add01 Enter the first number. First, type 97 and then press Enter. You will be asked for a second number, in a screen looking something like this: C>pcobrun add01 Enter the first number. 97 Enter the second number. Now type 33 and press Enter. The two numbers are added together and displayed: C>pcobrun add01 Enter the first number. 97 Enter the second number. 33 The result is: 130 C> |
Constant Variable & Display sample code
000100 IDENTIFICATION DIVISION. 000200 PROGRAM-ID. ADD01. 000300 ENVIRONMENT DIVISION. 000400 DATA DIVISION. 000500 000600 WORKING-STORAGE SECTION. 000700 000800 01 FIRST-NUMBER PICTURE IS 99. 000900 01 SECOND-NUMBER PICTURE IS 99. 001000 01 THE-RESULT PICTURE IS 999. 001100 001200 PROCEDURE DIVISION. 001300 001400 PROGRAM-BEGIN. 001500 001600 DISPLAY "Enter the first number.". 001700 001800 ACCEPT FIRST-NUMBER. 001900 002000 DISPLAY "Enter the second number.". 002100 002200 ACCEPT SECOND-NUMBER. 002300 002400 COMPUTE THE-RESULT = FIRST-NUMBER + SECOND-NUMBER. 002500 002600 DISPLAY "The result is:". 002700 DISPLAY THE-RESULT. 002800 002900 PROGRAM-DONE. 003000 STOP RUN. 003100 |

