Lab 3

Goals

  • use the debugger
  • system date/time
  • report preparation and calculation
  • perform and if statements

Part A – The Debugger

We will be using lab1b.cob to learn how to run the debugger. In the terminal window click the top right corner button, the one that looks like a box (not the dot) to maximize your terminal window. You can toggle this button to enlarge and reduce your terminal window. You MUST maximize your terminal window to run the debugger effectively (actually, you need to maximize the terminal window before the runcbl command). Once you have maximized your terminal window, type the following commands to first compile the program with debugging information and then to run the lab in the debugger:

ccbl -Zd lab1b.cob
runcbl -d lab1b

You will see a menu at the top of the window (press F10 to activate the menu at the top of the screen, if necessary), a source code area and a command area at the bottom. A list of debugger commands can be accessed by typing help in the command area (use the up and down arrow keys to scroll and press enter to exit the help screen). Typing q! on the command line will exit the debugger at any time. Notice that a black box exists to the left of the PERFORM statement in paragraph 000-CALCULATE-FUTURE-VALUES. This is the cursor for the debugger.

A few commands that you will use frequently are given below (do not try them yet!)

  • s single step; when you press s followed by enter the current statement will execute and the cursor in the source code area will move to the next executable statement in your program.
  • d will display the memory contents of a specified field; when you type d field-name followed by enter the value contained in that field will be shown in the command area.
  • b sets a break point so that execution will pause at a specified point in the program. However, a break point can only be set at the paragraph level (not the statement level). To use this command, you can type b parapgraph-name followed by enter.
  • gp – program executes to the end of the current paragraph.
  • g – program executes until you reach a break point or a STOP RUN.

Follow the next set of instructions and answer the questions:

Create a file called lab3ques.txt to hold the answers to the questions given below.

Compile the program appropriately and start the debugger

    1. What is the current value of NUMBER-ENTERED?
    2. Is the debugger case-sensitive?

Single step 4 times.

    1. What will be the next statement (in what paragraph) to be executed?

Single step 1 more time.

    1. What happened?

Single step 3 more times.

    1. What will be the next statement (in what paragraph) to be executed?

You will need to single step twice to enter each set of input data. When asked, enter 10000 for the investment amount, 10 for the number of years and 1000 for the yearly interest rate (remember, the program does not accept edited input. These inputs represent the values 10000, 10 and 10.00). Once you have entered the data the debugger cursor should be to the left of the statement MOVE INVESTMENT-AMOUNT TO FUTURE-VALUE.

Single step two more times.

    1. What is the current value of YEAR-COUNTER?

Set a breakpoint at paragraph 120-CALCULATE-NEXT-FV (A B should appear to the left of this paragraph name). Enter g twice.

    1. What is the current value of FUTURE-VALUE?

Enter g twice more.

8.   What is the current value of FUTURE-VALUE?

9.   How many more times do you have to enter g before something different happens?

10.        Why did you get there?

Enter 1 to perform another calculation and enter the same input information.

11.        What debugger command will clear all breakpoints? Use help.

Clear all breakpoints. Type g. When asked to end the program or perform another calculation, end the program.

Part B – Converting an Interactive Program to use File I/O

Convert lab1b to use file I/O. So, instead of inputting and outputting data to and from the terminal, you will input and output the data using files. Name this COBOL program lab3b.cob, the input file will be named lab3bin.dat and the output file lab3bout.dat. Your input data will include investment amount, number of years and yearly interest rate. Do not assume that you know how many sets of input you have. When you output the information be sure to do so nicely, similar to the following:

Your investment amount was $999,999,999.99
The number of years was 99
The yearly interest rate was 99.99%
The future value of your investment will be $999,999,999.99

You will need to create the input file yourself (just use an editor) that matches the file definition you have in the program. This must contain at least 5 records. This file must be submitted with your lab.

You can instead use report style output if you wish. Be sure to output the input values along with the results.

12.        What happens if you move data to the FD variable then try to WRITE the record?

13.        What happens if you move the output data to the record variable then try to WRITE using the FD variable?

14.        If you have already compiled the program but decide to change the input data in the file, do you have to recompile the program to run with the new data?

Part C – Writing A File I/O Program

Write a COBOL program (name it lab3c.cob) to accomplish the following: St. Nowhere Hospital would like to determine how much money in unpaid bills is still owed by people who have received patient care at their facility. Once they have a listing of all of the patients and the amount of each bill the hospital would also like to see the total amount still owed and the average amount owed per patient.

INPUT DESCRIPTION

The input file ~sgomori/students/cis314/lab3cin.dat has been created for you and has the following specifications for each billing recipient:

    • Patient Number – format 99999
    • Patient Name – format X(20)
    • Patient Address – format X(30)
    • Date Of Service – format 9(8) (MMDDYYYY)
    • Amount Owed – format 9(7)V99

Add to your select statement for the input file the following clause:

ORGANIZATION IS LINE SEQUENTIAL

and make sure the record description has exactly 72 bytes.

OUTPUT DESCRIPTION

Output the data to lab3cout.dat. You will need to keep track of the number of lines you have printed in order to advance to the next page at the appropriate time. Limit yourself to 65 lines per page. Underline the column headings by ADVANCING 0 LINES. You will need to use edited output for the dates and numeric data. The report format follows. Vertical formatting (line spacing) must match exactly. Horizontal formatting (columns) is up to you, but it must look nice (column headings centered over data, etc.)

Sample output:

 
MM/DD/YYYY                                      NAME OF HOSPITAL                               Page NN
HH:MM:SS
 
Patient            Patient                                                       Date Of           Amount
Number             Name                 Address                                  Service            Owed
-------            -------              -------                                  -------           ------
 00001            Johnson, William    2015 Neil Ave Columbus OH 43210           08/24/1999      $1,232,450.50
  ...                  ...                       ...                               ...              ... 
 
 
The average bill amount owed is:   $9,999,999.99
The total bill amount owed is:   $999,999,999.99

Submitting Lab 3

The files to submit are: lab3b.cob lab3bin.dat lab3c.cob lab3ques.txt

Deleting Unnecessary Files

See the clean utility described in Lab 2.