INTERNET COBOL - LAB 12 - CONTROL BREAK PROBLEM #1
![]()
A sales company wants a report of their sales people broken down by state. The company only sells in Connecticut, Massachusetts and Vermont from their home office in Sioux Falls.
The data file is organized by state. Here is the input file structure
FD SALES-FILE.
01 SALES-RECORD.
05
ID-IN
PIC XXXXX.
05
LAST-NAME-IN PIC X(10).
05
FIRST-NAME-IN PIC X(11).
05
SALES-IN
PIC 999999.
05
RETURNS-IN PIC
999999.
05
QUOTA-IN
PIC 999999.
05
STATE-IN
PIC XX.
88 Massachusetts VALUE "CT".
88 Vermont VALUE "MA".
88 Connecticut VALUE
"VT".
05
LEVEL-IN
PIC X.
88 HIGH-LEVEL VALUE "A".
88 MEDIUM-LEVEL VALUE "B".
88 LOW-LEVEL VALUE "C".
The level determines what sales are expected. Each salesperson has a quota to
reach (we will do very little with the quota in this problem). The commission
rates are as follows: for level A salespeople, they get 10% of the net-sales;
for level B salespeople, they get 7.5% (.075) of the net-sales, and for level C
salespeople, they get 5.5% (.055) of the net-sales.
![]()
This is a control break problem. When a new state gets read in, the control variable (in this case state) changes, and you will print out the totals for the previous state. Put each state on a new page.
![]()
Suggested solution:
The textbook has a solution for control break problems that is reasonable, but doesn't allow for heading lines within the control break. I have another suggestion.
A control break consists of two functions: a summary for the previous group (in this case state), and setting up for the next group. After you read in the first record, you need to perform just the setup routine. For regular breaks, you first will perform the summary routine, then the setup routine. After the last record is read, you will need to perform just the summary routine.
Here is part of my suggested code: (in pseudocode and COBOLeez)
1000-MAIN. PERFORM 2000-INITIALIZE. PERFORM 3000-PROCESS UNTIL END-OF-FILE = "YES". (note change . . .) PERFORM 3500-BREAK. PERFORM 4000-TERMINATE. STOP RUN.
2000-INITIALIZE. OPEN FILE. GET THE DATE AND MOVE TO THE HEADING DATE FIELDS. READ THE FIRST RECORD (note change . . .) PERFORM 3600-SETUP.
3000-PROCESS. IF STATE-IN <> PREVIOUS-STATE PERFORM 3500-SUMMARY PERFORM 3600-SETUP END-IF. <REGULAR PROCESSING>.
READ NEXT RECORD (note change . . .) AT END MOVE 'YES' TO END-OF-FILE END-READ.
. . . 3500-STATE-SUMMARY. MOVE SUMMARY DATA TO SUMMARY-OUTPUT-LINE. WRITE SUMMARY-OUTPUT-LINE. ADD SUMMARY DATA TO GRAND-TOTALS (IF DESIRED).
3600-SETUP. MOVE STATE-IN TO PREVIOUS-STATE. MOVE STATE-IN TO STATE-NAME-HL (heading-line) MOVE ZERO TO various totals. ADD 1 TO PAGE-COUNT (and other heading processes). WRITE REPORT-RECORD FROM HEADING-LINE(S).
(Note: Although my sample code says
"Read First Record" and "Read Next Record", it is the
standard "read" statement"
Read Sales File
at end move "YES" to end-of-file
End-Read.
Here
is my output