Separate speaker notes for
This slide presentation deals with modifications made to the Addda.cbl program during class and after.
This is the program that I started out with - addda.cbl.
It takes in user input for two numbers, adds them together using the add statement and displays the answer.
The ADD was done with the ADD statement. The ADD statement could eliminate the TO and it could be written without the TO and with commas between the fields. These options are shown on this slide with * in column 7 to make them comments.
The COMPUTE command uses signs. It puts the answer on the left of the equal sign and the mathematical formula on the right of the equal sign. The sign for adding is +, the sign for subtracting is -, the sign for multiplication is * and the sign for division is /.
This is the output that was produced when I used the compute statement. Note that the user entered 5 or the first number and 6 for the second number. The program has calculated and displayed the answer of 0011. It is now waiting for the user to press enter.
This COMPUTE in this program uses the add and the multiply. Note that the program follows the order of operation which says that multiplication is done before addition. Therefore SECOND-NUMBER will be multiplied by 2 and that answer will be added to FIRST-NUMBER.
This is the mathematical order of operation that is used with the compute.
Output from ADDDA1A.INT. The user entered 5 and then 6. The 6 is multiplied by 2 giving us 12 and then this is added to the 5 giving an answer of 0017.
Now I have put the addition in parenthesis so it will be done first. When the two numbers have been added together, the results will be multiplied by 2.
Since the parentheses are here, the 5 and 6 are added first and then the result is multiplied by 2.
This program uses the ADD followed by the MULTIPLY to accomplish the same thing that we saw on the previous slide. The difference here, is that both the results of the ADD and the results of the MULTIPLY are available for use.
The add is done and the answer is stored in ADD-ANS. Then the number in ADD-ANS is multiplied by 2 and the answer is stored in FINAL-ANS.
Note that both are displayed.
Notice that both answers are displayed. First ADD-ANS which is 29 and then FINAL-ANS which is 58.
Notice that we are starting to get more and more in working storage and in fact some of these things really do not belong in the input area. I need to break them up better and have an input area and an output area. In fact, this does not effect the program at all - it is just a better organization of the data. In the next slide, I am going to take this one step further.
In this slide, I have broken WORKING-STORAGE up into three groups: INPUT-AREA, WORK-AREA and OUTPUT-AREA. The data that is coming in is in the INPUT-AREA. The data that is the result of calculations is stored in the WORK-AREA and I have added -WS to distinguish them. The data that will be displayed as output is in the OUTPUT-AREA and I have added the -OUT to distinguish them. Remember, all items defined in the program have to have unique names so I could not call two things by the name ADD-ANS. By having ADD-ANS-WS as the place where the answer is put and ADD-ANS-OUT as the place where the data to be displayed is stored I can distinguish them and still know I am talking about the same number.
See the notes on editing for more information.
Note that mathematical calculations should be done with pure math fields. An assumed decimal point keeps the field a pure math field. When editing characters are added, it changes this. Some COBOLS can use non pure math fields in calculations, many cannot so it is a good programming practice to do the math using the pure fields and move them to the edited fields when the viewer wants to see them.
This slide shows output using decimal numbers.
In this slide I am using a subtract and I realize that I may get a negative answer if FIRST-NUMBER is bigger than SECOND-NUMBER. To deal with the possibility of negative answers, you put an S in the picture with the input or the work area definitions. The S remembers the sign. Because people want to see the actual sign, you set up the output to show the actual sign. In one of these examples, I have the sign before the data and in one example, the sign is after the data. Look at the output on the next page to see the results. You should also read the notes on data editing.
See notes on editing for other ways that negative data can be handled.
On this slide I gave the input an S in the picture so the user could enter negative data.
The program is now set to deal with negative data. Check the notes on editing for more information.