首页 > > 详细

代写INFO3105 Week 3 Class 1

INFO3105 Week 3 Class 1
Review
Numeric Edited fields
Lab4
Introduction to Summary Report Programming with COBOL
Definition of a Control Break – “A change of category used to trigger a subtotal. For example, if
data are sub totaled by province, a control break occurs when BC changes to ON.” Lots of COBOL
programs/reports are written as control break programs. The first pre-requisite to
writing a control break program has nothing to do with the program itself; rather it’s the
data that you need to be concerned with. The data must be sorted on the control break
field; therefore if we were using the example given in the above definition, the data
would have had to be sorted on province. Below we see the layout of the control break
program we’ll be working on next:
Notice that the report is written so that all of the salespeople from a particular branch
are listed on a single page. Which field would the data for this report sorted by? Well
obviously it’s the branch number field. Below is some of the data used by this report,
see if you can locate the branch information in it:
And here is the file layout for this data
:
The data here shows salespeople for
branches 100 and 200
So returning to the output we see we need to produce at least 3 different types of
output:
1. Heading information (at the top of page)
2. Detailed information (actual sales person data)
3. Summary information (branch totals).
So what you need to do is lay the report out to see where everything fits, historically
programmers would use something called a Printer Spacing Chart see page 95 of the
text for an example. Then once the design of the report is done, you can map the
columns to the layout in COBOL, for instance here is the 1st Heading Line for the report
from page 1:
We see here there are some fields designated with the keyword “FILLER”. This tells the
compiler basically what we have is some space to allocate but we can’t reference it
directly as variable. Use filler when the data isn’t important to the logic of the program.
Constant strings are embedded in quotation marks this is known traditionally as hard
coding the data. The keyword SPACES is used to put blanks in each character
designated by the PIC X(..) clause. So instead of counting out 5 actual spaces we can
just write it as PIC X(5) VALUE SPACES. One other point to take note of is the picture
clauses used here. PIC 9 is for numeric data, PIC X is for alphanumeric, and PIC Z9 is
for formatted numeric data, it indicates if there is number is not large enough to
encompass the entire picture clause just place spaces (instead of zeroes) in the leading
characters.
Returning to the listing on page 1, how many different lines of output do you need to
create? The answer is 7 (there are actually 9 but the 8th and 9th aren’t visible here, see
below for the final lines example).
We saw how to write the individual lines out in our labs 1-3. In labs 1-3 the output was
basically the same as our input. Here the last two report columns do not exist in the
data but are actually to be calculated by our program based on the data. The net sales
column is simply gross sales subtract returns. The commission column is calculated as
net sales multiplied by a commission rate (last column of the input data).
To summarize, the 9 different line layouts you need to create are:
1. Heading line 1 – page no, and date
2. Heading line 2 – constant with Salesperson By Branch text
3. Heading line 3 – Branch indicator
4. Heading line 4 – Individual Column Headings
5. Detail line – containing individual salesperson data
6. Branch Total – containing branch totals (formatted) for each columns
7. Single Underlines – typical in a report like this under the branch totals (see
below)
8. Grand Totals – containing accumulation of Branch Totals (formatted)
9. Double Underlines – indicates the end of Report (just use the “=” instead of ‘-‘)
End of the Report
Detail Line Formatting
The first four headings are relatively straight forward to layout. Line 5 (the detail line) will
ask you to format the numeric fields and the last two fields need to be “Computed”.
Page 195 of the text lists all of the different ways to format data. We’ll be using
something similar to the last one with the $ signs but without CR designation.
COBOL only lets you do math on numeric fields, NOT on numeric edited fields. So
you’ll have to typically follow this pattern with numeric fields that require calculations:
1. move the input to a working storage field
2. do some math on the working storage field
3. move the working storage field to the numeric edited field
Let’s see the syntax for doing the 3 steps by looking at what goes on in the detail line
with the Net Sales column: Assuming we have done our READ, we would calculate our
Net Sales field as follows:
 Calculate the difference of the Gross Sales and Sales Returns :
COMPUTE WS-NET-SALES = SALESPERSON-GROSS-SALES -
SALESPERSON-RETURN-SALES
 Move the working storage field (unedited) to the edited field
o 05 WS-NET-SALES PIC S9(7)V99 VALUE ZERO.
o ..
o ..
o 05 WS-SL-SLSP-NET PIC $$$,$$$.99.
o ..
o ..
o MOVE WS-NET-SALES TO WS-SL-SLSP-NET
When calculating commissions we need to worry about rounding and we can do this
with the keyword ROUNDED (page 32 of the text) as follows:
Lab 5 - 2%
 Submit to the FOL dropbox (no need to get the full program working yet):
1. the source code for the 9 different output lines (including output field
definitions)
2. the source code for a paragraph called SALESPERSON-CALCULATIONS
that contains all of the compute statements for the report (remember you’ll
need both branch and grand totals)
Also, read pages 316-318 of the text.

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!