Upon completion of this chapter, you should be able to
Define the term "control field" as it relates to control break processing.
Describe and demonstrate how logical files are used in control break programs.
Describe and demonstrate the use of single-level and multiple-level control break programs.
Thus far, we have focused on detail printing, in which one or more lines are printed for each input record read. Sometimes, however, a user may request that a report include total or summary lines for a group of records. As the name suggests, a summary or group report summarizes totals that provide more comprehensive and meaningful information for the user than a detail or exception report.
The report in Figure 12.1 is an example of a summary report in which the total hours worked for each department are summarized and printed. In addition, the total company hours are accumulated and printed at the bottom on the report. Summary printing can be performed either in place of, or in addition to, detail printing.
Quite often reports include detail and summary information. For example, in Figure 12.2 each employee is listed showing the number of hours worked. In addition, a summary of the total hours for each department is printed for each department.
This chapter considers a type of summary procedure called control break processing in which control fields are used to indicate when totals are to print.
In this case problem, the payroll manager of the Best Deal Stores Company wishes to determine the total sales for each department as shown in the printer spacing chart in Figure 12.3.
The input file for this program is the employee pay file (EMPPAYPF) in Figure 12.4 that consists of employee records.
To produce a report with sales totals by department, the input file must be in department number sequence. That is, all records pertaining to employees in department 111 are followed by all records pertaining to employees in department 222, and so on.
Most often, data files are not in the required sequence for preparing a report based on control break logic. The EMPPAYPF file in Figure 12.4 is a physical file containing the actual employee pay data and is keyed on Employee Number. For this case problem, reading the data directly from the EMPPAYPF physical file will not return the data in the required sequence, that is, in department number sequence.
A logical file must be created over the EMPPAYPF physical file so that the records are read into the program in department number sequence. Figure 12.5 illustrates the systems flowchart for file processing when a logical file is used in a control break program to access data from a physical file. The logical file EMPPAYL12A in Figure 12.6 provides the access path to the physical file and ensures that records from the EMPPAYPF physical file are read into the program in department number order.
Note that there are two key fields in the EMPPAYL12A logical file. Employee number (EMPLOYEENO) is specified as the secondary key so that the employee records are in employee number sequence within each department. Employee number is strictly used to sequence records and is not used in the processing of the records in the program.
Systems flowchart
This program reads records from the logical file EMPPAYL12A that are in sequence by department number. When a record is read that contains a department number that is different from the previous record, a total sales line for the previous department is printed.
There may be numerous employee records for department 111, department 222, and so on. That is, there may be several records with the same department number, depending on the number of employees within a given department. The output is a report that prints not only each employee's sales but also every department's total sales amount.
For this problem, detail printing is required; that is, each input record containing department number, employee number, and sales is printed. Software developers would recommend such detail printing only if the user must see data from each input record. In addition to detail printing, summary lines indicating department totals are printed. Thus, in this example, group printing is also required, where a total line is printed for each department.
Detail lines print in the usual way, after each input record is read and processed. In addition, after each input record is read, the value in the sales field in that record is added to a department total. This department total is printed whenever a change in department number occurs. Since a change in department number triggers the printing of a department total, department number is called the control field.
After all employee records for department 111 are read and printed, a total for department 111 is printed. Similarly, after all records for department 222 are read and printed, a total for department 222 is printed, and so on. This type of processing requires the file of input records to be in sequence by department number. By using the logical file EMPPAYL12A, records are maintained in department number sequence, allowing the program to accumulate a total and print it at the end of each department group.
Thus, all employee records for department 111 are read and printed, and a department total is accumulated. This processing continues until an employee record is read that contains a department number different from the previous one. When a record with a different department number is read, then the total for the previous department is printed. Thus, the first input record pertaining to an employee in department 222 causes a total for department 111 to print. Since totals are printed after a change occurs in department number, which is the control field, we call this type of group processing control break processing. Figure 12.7 presents the steps the program executes to perform the control break procedure.
Usually a program is designed at the planning stage with a hierarchy chart and either a flowchart or pseudocode. Figures 12.8 and 12.9 illustrate the hierarchy chart and pseudocode used to prepare this program. Study the hierarchy
chart and pseudocode carefully so that you understand the structure to be used in the program. The program that performs the control break procedure is shown in Figure 12.10 and is discussed in detail in the next section.
Program CPCH12A produces the sales report in Figure 12.11. The logical file EMPPAYL12A is keyed on department number and employee number. When the logical file accesses the data from the physical file, the logical file maintains the records in employee number order within department number. Thus, the program prints the employee numbers in sequence within each department number.
For each record read, the program performs two detail functions:
Prints a detail line, with the department number, employee number, and sales.
Adds EP-SALES to a department total called WS-DEPARTMENT-TOTAL.
In addition, the total line, TOTAL FOR DEPARTMENT IS $$, $$$, $$9.99-, will print only after the first record with the next department is read. After this total prints, WS-DEPARTMENT-TOTAL is reinitialized to zero and the new input record is processed as in steps 1 and 2 above.
This is called a single-level control break because we have only one field, DEPARTMENT, that triggers the printing of totals. For single-level control break processing, the following steps must be specified after the files have been opened:
Establish a hold area with the contents of the first record's control field. This is performed in the intialization routine that is executed from the main module. This will eliminate a false control break during the first execution of the loop.
After the files are opened, the first input record is read and its control field, in this case EP-DEPARTMENT, is moved to the WS-PREVIOUS-DEPARTMENT field in WORKING-STORAGE area to save it for comparing to the next record's department number. Thus, our main module and initialization routine would include:
Process input records at 200-PROCESS-RECORD-RTN. Processing depends on whether or not the control field read in matches the one stored in the WS-PREVIOUS-DEPARTMENT field.
The full procedure for 200-PROCESS-RECORD-RTN is
We begin at 200-PROCESS-RECORD-RTN by comparing EP-DEPARTMENT to WS-PREVIOUS-DEPARTMENT. The first time through 200-PROCESS-RECORD-RTN, WS-PREVIOUS-DEPARTMENT and EP-DEPARTMENT are equal because EP-DEPARTMENT was moved to WS-PREVIOUS-DEPARTMENT in the initialization module. For all subsequent passes through 200-PROCESS-RECORD-RTN, WS-PREVIOUS-DEPARTMENT will contain the EP-DEPARTMENT of the previous record read. When WS-PREVIOUS-DEPARTMENT and EP-DEPARTMENT are equal, there is no control break, and the program performs the following three steps in the detail processing phase:
The module 220-WRITE-DETAIL-LINE-RTN is performed to move input data to a detail line, print the line, and increment the line counter as in Figure 12.12.
The program checks for page overflow with a line-counter procedure in 220-WRITE-DETAIL-LINE-RTN. When the field called WS-LINE-COUNTER exceeds WS-LINE-LIMIT, the program performs 225-HEADING-RTN that prints headings on a new page and reinitializes WS-LINE-COUNTER to 7. WS-LINE-LIMIT is initialized at 60 in WORKING-STORAGE.
The sales (EP-SALES) of the current record are added to the department accumulator field WS-DEPARTMENT-TOTAL.
The module 230-READ-RECORD-RTN is performed to read the next record.
The program continues to process input records until the value in the EP-DEPARTMENT field from an input record is different from the previous department number stored in WS-PREVIOUS-DEPTARTMENT. When they are different, a control break has occurred. Thus, each time EP-DEPARTMENT is not equal to WS-PREVIOUS-DEPARTMENT the program performs the 210-DEPT-CONTROL-BREAK-RTN procedure, where the accumulated department total is printed.
3. Print a summary line in the 210-DEPT-CONTROL-BREAK-RTN module after a record is read that has a different department number than the one stored in WS-PREVIOUS-DEPARTMENT.
Consider the following 210-DEPT-CONTROL-BREAK-RTN module.
210-DEPT-CONTROL-BREAK-RTN is performed when an input record's EP-DEPARTMENT field, the control field, differs from the one stored in WS-PREVIOUS-DEPARTMENT. As we have seen, WS-PREVIOUS-DEPARTMENT contains the previous EP-DEPARTMENT. When there is a change in EP-DEPARTMENT, the program will
Print a line with the department total accumulated for the previous department control group, which is stored in WS-DEPARTMENT-TOTAL.
Reinitialize WS-DEPARTMENT-TOTAL, the control total, so that the next department's total begins at zero before any amounts for the new control group have been accumulated.
Move the current EP-DEPARTMENT to WS-PREVIOUS-DEPARTMENT so the program can compare succeeding input records to this new EP-DEPARTMENT control field.
Return to 200-PROCESS-RECORD-RTN and process the current record that involves (1) printing a detail line and (2) adding EP-SALES to WS-DEPARTMENT-TOTAL.
Regardless of whether a control break procedure is executed, the detail data in the current record are printed, and the amount is added to WS-DEPARTMENT-TOTAL before a new record is read.
4. Process the last department total when NO-MORE-RECORDS is TRUE.
What remains is the processing of the very last control total when an end-of-file condition is reached. This is accomplished by forcing a control break.
Control break printing of totals occurs when a record with a new control field is read. The total for the last group of records, then, will have been accumulated when there are NO-MORE-RECORDS, but a control total will not have been printed since there is no subsequent record to trigger a change. Consider the following:
DEPARTMENT 111 111 111 Total for Department 111 ← Dept 111 totals are printed when the first record from Dept 222 is read 222 222 222 222 Total for Department 222 ← Dept 222 totals are printed when the first record from Dept 333 is read 333 333 (no more record) ← At this point, the printing of 333 totals must be "forced" after NO-MORE-RECORDS is set to TRUE.
We need to include a procedure to print the total for department 333. In the 300-TERMINATION-RTN, after 200-PROCESS-RECORD-RTN has been executed and there are NO-MORE-RECORDS, we must force a printing of this final total.
The refinements discussed in this section are shown in the output specifications in Figure 12.13. These include
Printing a final total.
Group suppression of a control field.
Printing the control field with the control break total line.
Sometimes, control break processing requires the printing of a summary line containing a final total. This would be printed after the last control total is printed.
The final total, WS-FINAL-TOTAL, may be accumulated by adding each WS-DEPARTMENT-TOTAL to it in 210-DEPT-CONTROL-BREAK-RTN. This means that WS-FINAL-TOTAL would be accumulated, not for each detail record, but only when a control break has occurred. This is accomplished by including the following ADD statement in 200-DEPT-CONTROL-BREAK-RTN before WS-DEPARTMENT-TOTAL is reinitialized to zero:
Within the employee pay file (EMPPAYPF), there are usually several employee records with the same department number, depending on the number of people within a given department. If you examine the sales report in Figure 12.11 again, you will see that the department number prints on each detail line and is duplicated down the page as each detail record is printed for the same department. However, in Figure 12.13, the department prints only once for each department or group.
It is unnecessary to print the department number each time a detail line is printed, since it will always be the same until a control break occurs on department number. Thus, the program can be changed to print the department number only once at the beginning of each control break. In this way, department 111 is assumed for all subsequent records in that group and redundant information is suppressed. The next group, department 222, is highlighted by having its department number print only once at the beginning of the group.
The output field DL-DEPARTMENT, then, is referred to as a group indicate field. Changes, indicated below in bold, are required to accomplish suppression of a group indicate field.
The statement MOVE EP-DEPARTMENT TO DL-DEPARTMENT contained in the first program example (CPCH12A) has been removed from the 220-WRITE-DETAIL-LINE-RTN module. Since this statement moves the department number to the print area for each detail print line, it must be removed to incorporate group indication of the control field.
In the 220-WRITE-DETAIL-LINE-RTN, the statement INITIALIZE DL-DEPARTMENT is placed after the detail write statement. This INITIALIZE statement sets DL-DEPARTMENT to zeros since it is a numeric report-item. Since DL-DEPARTMENT has a PIC of Z(3), it will print as spaces because of zero suppression. This statement allows the program to clear the department number field for subsequent records that have the same department number.
To print the department number for the first record of each department group, the MOVE statement in 210-DEPT-CONTROL-BREAK-RTN is modified as follows:
The 210-DEPT-CONTROL-BREAK-RTN module is performed only when a control break occurs. This means that the current detail record is the first record of the next group. Since we wish to print the department number only for the first record of each group, EP-DEPARTMENT is moved to DL-DEPARTMENT in the control break module. When the detail record is printed in 220-WRITE-DETAIL-LINE-RTN, the department number will appear on the report. It is then initialized, or set to zero, at the end of 220-WRITE-DETAIL-LINE-RTN.
When using the group indicate procedure, a problem may occur if a detail record belonging to the same group forces page overflow. For example, suppose the detail records for department 333 are printing toward the bottom of the page.
A department 333 record then causes page overflow. The program jumps to the next page and prints the headings and the next detail record, which is also department 333. However, in this case the department number does not print because it was initialized to zero.
If this happens, the first detail record on the next page will not contain the department number because it prints only when there is a control break. Therefore, to make the report more meaningful, we add the following statement before the detail WRITE statement in 220-WRITE-DETAIL-LINE-RTN:
Thus, when an overflow condition occurs in the middle of a group of records that contain the same department number, we move the department number to DL-DEPARTMENT. When the detail line is printed on the first line of the page, it will contain the department number.
With this group indicate procedure, we specify the department number to print when one of two conditions occurs:
When printing the first record of a group of records.
When overflow occurs in the middle of a group of records that contain the same department number.
When printing a control break total, it is more desirable to identify which group the total represents. Consider the following statement:
TOTAL FOR DEPARTMENT 111 IS $$, $$$, $$9.99*
This statement identifies which department the total has been accumulated for. This provides the user with more meaningful information.
To print the department number in the department total line, a new field called TL-DEPARTMENT is added to the total line defined in WORKING-STORAGE:
Before the total line is printed in 210-DEPT-CONTROL-BREAK-RTN, the WS-PREVIOUS-DEPARTMENT field is moved to TL-DEPARTMENT. This ensures that when the total line is printed it always contains the department number of the group that the total line is being printed for. The MOVE statement is added at the beginning of 210-DEPT-CONTROL-BREAK-RTN before the total line is written to the report.
Consider 300-TERMINATION-RTN in Figure 12.10, in which we move WS-DEPARTMENT-TOTAL TO TL-DEPARTMENT-TOTAL and WRITE the last output line. This MOVE and WRITE could be replaced with
PERFORM 210-DEPT-CONTROL-BREAK-RTN.
Since we wish to "force" a control break at the end of the job, it is best to perform the sequence of steps in the control break routine rather than duplicate the instructions in the end-of-job module. Consider, however, the last statements of the control break procedure, 210-DEPT-CONTROL-BREAK-RTN:
Once the last record has been read and processed and an AT END condition has been reached, these instructions are really not necessary. To avoid performing them on an AT END condition, we write the last sentence of the 210-DEPT-CONTROL-BREAK-RTN module as
WS-LINE-COUNTER is incremented by three, WS-DEPARTMENT-TOTAL is initialized to zero, and the new EP-DEPARTMENT is stored only if an AT END
condition has not been reached. Thus, our main module may be written with the following:
Another reason for testing for more records is to print new headings in a control break program only if an AT END condition has not occurred. Otherwise, the last page of the report would just contain headings, and this would be incorrect.
The full single-level control break program that includes all the preceding refinements is illustrated in Figure 12.14.
The report in Figure 12.15 is produced from program CPCH12B.
In this case problem, the payroll department of the Best Deal Stores Company wishes to print a summary report, as shown in Figure 12.16. This report summarizes the total sales by department for each store within the company.
Examine Figure 12.16 and you will see that the primary focus of the report is store number. Within each store, totals are listed by department number. No detail printing is required here; rather, the program results in group printing of department totals and store totals. The printing of an EP-DEPARTMENT total line is performed after all records for a given EP-DEPARTMENT have been processed. Moreover, an EP-STORE-NUMBER total and headings for the next EP-STORE-NUMBER are printed when there is a change in EP-STORE-NUMBER.
The data necessary for this problem are stored in the employee pay file (EMPPAYPF). The difference between this input and the input used in the earlier case problems is that the records are required in department number sequence within each store number. The input file is keyed so that all employee records for STORE 1133 DEPARTMENT 111 appear first, followed by all employee records for STORE 1133 DEPARTMENT 222, and so on. Thus, the following input is a sample of what you might expect:
EP-STORE | EP-DEPARTMENT | EP-SALES |
---|---|---|
1133 | 111 | 1127.23 |
1133 | 111 | 1100.14 |
1133 | 111 | 1027.45 |
1133 | 222 | 1052.23 |
1133 | 222 | 1126.27 |
1133 | 333 | 1223.28 |
2257 | 111 | 1111.14 |
2257 | 111 | 1027.23 |
2257 | 444 | 1398.50 |
4464 | 222 | 1100.26 |
Note that the first six records are in department number sequence within store number 1133.
The next group of records for store 2257 is in sequence by department number.
The program accumulates the total sales for each department before printing a line. Thus, if EP-DEPARTMENT 111 in EP-STORE-NUMBER 1133 has three employees entered in three separate input records, the program prints one line after all three records have been read and totaled.
We have, then, two control fields: EP-DEPARTMENT is the minor control field, and EP-STORE-NUMBER is the major control field. Records are in sequence by EP-DEPARTMENT within EP-STORE. Note that for a given department within a particular store there may be numerous employee records.
For accurate control break processing, records must be in sequence by the fields in which totals are going to be calculated. These fields are called control fields. In this example, the control fields are store number and department number because the sales for employees are accumulated into totals by department and store. The logical file, shown in Figure 12.17, is used to retrieve the records in the desired sequence, that is, department number within store number. The actual data are retrieved from the EMPPAYPF physical file.
The keyword UNIQUE is not specified at the file level to allow the logical file to contain keys that have duplicate values. Each store may contain numerous records for a particular department. Likewise, more than one person can work in a particular department.
Since the required data for this program resides in the EMPPAYPF file, the file-level keyword PFILE specified in the keyword field (position 45–80) is used to associate this logical file with the physical file (PFILE) EMPPAYPF.
The key fields are defined on lines 7.00 and 8.00. Line 7.00 defines STORENO as the primary key because it is the first key field to be listed. Line 8.00 defines DEPARTMENT as the secondary key field. This means that the records are sorted by department number within each store number.
Since this logical file is built over the physical file and is used to retrieve records from the EMPPAYPF, it is this logical file that sorts and maintains the key sequence of the records for this program.
Examine the planning tools used to prepare this control break program. The hierarchy chart is in Figure 12.18, and the pseudocode is in Figure 12.19. The COBOL/400 program for this two-level control break procedure is illustrated in Figure 12.20.
Pseudocode
The report in Figure 12.21 is produced from program CPCH12C. Each store is printed on a separate page with sales totals for each department.
It is likely that the pages for each store will be distributed to different users. For example, the pages pertaining to STORE 1133 will be distributed to users in STORE 1133; the pages for STORE 2257 might go to that store, and so on. In this instance, it would be redundant to print the Store Number on each detail line. Rather, it would be better to print it once at the beginning of each page as a page heading.
Thus, a control break module would include a statement to PERFORM the heading routine so that the paper is advanced to a new page when a control break occurs. In this example, we wish to print headings at the beginning of each new store; thus, the PERFORM statement is included in the 220-STORE-CONTROL-BREAK-RTN.
Let us begin by considering 100-INITIALIZATION-RTN.
In this program, two control fields are required. Thus, a double-level control break procedure is used. We need two hold areas for comparison purposes, one for EP-STORE-NUMBER and one for EP-DEPARTMENT. Once the first record is read in 100-INITIALIZATION-RTN, the control fields must be moved to hold areas. This establishes WS-PREVIOUS-DEPARTMENT and WS-PREVIOUS-STORE-NUMBER fields, which are used to determine if a control break has occurred in 200-PROCESS-RECORD-RTN.
Also, 225-HEADING-RTN is performed from 100-INITIALIZATION-RTN so that headings are printed for the first EP-STORE group. These headings must be printed after the initial READ statement so the store number of the first store group is available for printing.
At 200-PROCESS-RECORD-RTN the program compares the two control fields to their respective hold areas. If there is no change in either EP-STORE-NUMBER or EP-DEPARTMENT, the program adds the EP-SALES to a WS-DEPARTMENT-TOTAL and reads the next record. Since there is no detail printing required, there is no WRITE in 200-PROCESS-RECORD-RTN.
The first statement in the detail processing module, 200-PROCESS-RECORD-RTN, is to check to see if a control break has occurred. This must be done before any detail processing is performed because, if a change has occurred, the control totals for the previous group must be printed before any detail processing can occur. Notice that a nested IF statement is used to determine if a change has occurred in EP-STORE-NUMBER or EP-DEPARTMENT. If there is a control break on EP-STORE, the program executes 210-DEPT-CONTROL-BREAK-RTN and 220-STORE-CONTROL-BREAK-RTN.
The minor control break is always performed first. That is, the first thing we do when there is a change in EP-STORE-NUMBER is to process the last department total for the previous department. This not only prints the previous department's total, but it adds that department's total to the store total, initializes WS-DEPARTMENT-TOTAL to zero, and moves the new EP-DEPARTMENT to WS-DEPARTMENT.
After 210-DEPT-CONTROL-BREAK-RTN is executed, 220-STORE-CONTROL-BREAK-RTN must be performed next to print the store total. 220-STORE-CONTROL-BREAK-RTN performs the following steps:
Print the WS-STORE-NUMBER-TOTAL.
Reinitialize the WS-STORE-NUMBER-TOTAL to zero.
Move EP-STORE-NUMBER to WS-STORE-NUMBER.
Print a heading on a new page.
Thus, 220-STORE-CONTROL-BREAK-RTN is written as
When there is a change in EP-STORE, this is considered a major control break. Note that we test for a major control break in 200-PROCESS-RECORD-RTN before we test for a minor control break. As a result, the major-level control routine will begin by performing a minor-level control-break.
Recall that the last statement in 220-STORE-CONTROL-BREAK-RTN ensures that we store the new EP-STORE-NUMBER and print a heading in all instances except after an AT END condition. This is required because 220-STORE-CONTROL-BREAK-RTN will be executed (1) from 200-PROCESS-RECORD-RTN and (2) after all records have been processed, when we must force a break.
When a change in EP-DEPARTMENT occurs even without a change in EP-STORE-NUMBER, a minor control break occurs, and 210-DEPT-CONTROL-BREAK-
RTN is executed. Thus, when EP-DEPARTMENT is not equal to WS-PREVIOUS-DEPARTMENT or when a department break has occurred, we do the following:
Print the total for the previous EP-DEPARTMENT.
Add that total to a WS-DEPARTMENT-TOTAL.
Initialize the WS-DEPARTMENT-TOTAL field to zero.
Move the new EP-DEPARTMENT to WS-PREVIOUS-DEPARTMENT.
This would be performed as follows:
In 210-DEPT-CONTROL-BREAK-RTN and 220-STORE-CONTROL-BREAK-RTN, there are instructions that are to be executed under normal conditions but not on an AT END condition. These instructions are preceded with an IF MORE-RECORDS clause to ensure that they are not executed when an AT END condition occurs.
The program tests for more records in 210-DEPT-CONTROL-BREAK-RTN and 220-STORE-CONTROL-BREAK-RTN because we want to avoid moving EP-DEPARTMENT or EP-STORE-NUMBER after an AT END condition has been met. Also, there would be no need to increase the line counter or initialize the hold fields.
After all records have been read and processed and an AT END condition occurs, control returns to the main module, where 300-TERMINATION-RTN is executed. As with single-level control break processing, we must force a break at this point so that we print the last EP-DEPARTMENT total and the last EP-STORE-NUMBER total. To accomplish this, we perform 210-DEPT-CONTROL-BREAK-RTN and 220-STORE-CONTROL-BREAK-RTN from 300-TERMINATION-RTN after all records have been processed.
Note that 200-PROCESS-RECORD-RTN could include an EVALUATE in place of the two conditionals that test for control breaks.
EVALUATE-TRUE . . . enables the program to test two or more separate conditions. When the first condition is met, that is, store number changes, 210-DEPT-CONTROL-BREAK-RTN and 220-STORE-CONTROL-BREAK-RTN are executed, and the statement terminates. When there is a change in department number but no change in store number, 210-DEPT-CONTROL-BREAK-RTN is executed. If neither control field changes, then the ADD and READ are the only imperative statements executed in 200-PROCESS-RECORD-RTN.
Three types of report that can be produced are
Detail or transaction reports.
Exception reports.
Summary or group reports.
In a control break program, all input records must be in sequence by minor control fields within intermediate control fields within major control fields. If the records are not already in this order, then the file must be sequenced into the required order before it can be processed.
Files required for control-break processing can be reorganized into the proper sequence by using logical files.
Control break routines are executed as follows:
Higher-level breaks force lower-level breaks.
Appropriate control total line is printed.
Appropriate control field is initialized.
Appropriate control total field is initialized.
1. When a double-level control break is used, input data must be in sequence by major fields within minor fields.
2. To execute a control break program, input data must be in sequence by the control fields.
3. Before a detail or calculation routine is executed from the main module of a control break program, the control fields must be moved to hold areas in WORKING-STORAGE.
4. If there are numerous control breaks to be performed, major level breaks should force minor level breaks.
5. After a control break has occurred, the hold field should be initialized to zero.
6. The detail module of a control break program always has a WRITE statement.
7. The control break module must always clear the total fields to zero.
8. The control break module typically includes a WRITE statement.
9. A maximum of two levels of control breaks is permitted in a control break program.
10. If each control group is to begin on a separate page, we would perform a heading routine at the control break module.
In control break processing, we typically MOVE the control field to ___ after reading the first record.
If a final total is required, it is most efficient to accumulate the final total in the ___ module.
At the control break module, we must print ___, initialize ___ at zero, and move ___.
When each individual input record results in the printing of an output line, we call this ___.
If multiple control breaks are used in a program, the routine for producing the major-level control break would always begin by performing ___.
What processing is performed if an input control field is equal to the control field stored in the hold area?
What processing is performed if an input control field is not equal to the control field stored in the hold area?
Consider the following problem definition. Each input record includes (1) a warehouse number where the item is stocked and (2) the value of that item's stock on hand.
Record description layout for inventory file
Field Description | Type | Size | COBOL Field-name |
---|---|---|---|
Region Number | S | 3,0 | REGION-NUMBER |
Warehouse Number | S | 2,0 | WAREHOUSE-NUMBER |
Item Number | S | 5,0 | ITEM-NUMBER |
Quantity on Hand | P | 7,2 | QUANTITY-ON-HAND |
Unit Price | P | 5,2 | UNIT-PRICE |
Printer spacing chart for inventory report
If the output report consists of each region's total value of inventory, we would call this a ___ report.
To print region totals using the format described in this chapter, input data must be in sequence by ___.
Write the main module for this problem.
Assuming that you have labeled the detail module 200-PROCESS-RECORD-RTN, write that module.
Assuming that you have labeled the control break module 210-CONTROL-BREAK-RTN, write that module.
Suppose you have the following sentence in the control break module:
THERE-ARE-MORE-RECORDS is a condition-name equivalent to the condition IF ARE-THERE-MORE-RECORDS = 'YES'. Why should we check this condition before we MOVE REGION-NUMBER TO WS-PREVIOUS-REGION-NUMBER?
Consider the following coding:
Is the overall logical structure correct?
After executing PERFORM 200-PROCESS-RECORD-RTN UNTIL NO-MORE-RECORDS in the main module, should there be a PERFORM to print the last control group? Explain your answer.
There are two instructions missing from 200-DETAIL-RTN that will result in logic errors. Insert them.
Suppose 200-PROCESS-RECORD-RTN had a READ as its last instruction. How would this affect processing?
Suppose we omitted the MOVE statement from the main module. Would this have any substantial effect on the processing? Explain your answer.
Write a program to produce the payroll report described in the printer spacing chart below. This problem requires a double-level control break program.
Record description layout for employee file
Field Description | Type | Size | COBOL Field-name |
---|---|---|---|
Department Number | S | 2,0 | DEPARTMENT-NUMBER |
Territory Number | S | 2,0 | TERRITORY-NUMBER |
Employee Number | S | 3,0 | EMPLOYEE-NUMBER |
Employee Name | A | 20 | EMPLOYEE-NAME |
Annual Salary | P | 5,0 | ANNUAL-SALARY |
Printer spacing chart for payroll report
Pseudocode
Write a program to print a sales report. The data are contained in a physical sales file that is not keyed and in no particular order. Thus, a logical file will have to be created over the physical file so the program will receive records in Day sequence. The problem definition is shown below.
Notes:
There is a record for each sale made by an employee; thus there are an undetermined number of input records.
Records must be in sequence by day number, which ranges from 1 to 5 (Monday–Friday).
Systems flowchart
Record description layout for physical sales file
Field Description | Type | Size | COBOL Field-name |
---|---|---|---|
Employee Number | S | 3,0 | EMPLOYEE-NUMBER |
Day Number | S | 1,0 | DAY-NUMBER |
Amount of Sale | P | 7,2 | AMOUNT-OF-SALES |
Printer spacing chart for weekly sales report
Write a program to print a total salary by territory report. The data are contained in a nonkeyed physical salary file that is in no particular sequence. The problem definition is shown below.
Notes:
The program must receive the records in sequence by territory number.
Print the total salaries for each territory. At the end of the report, print the total salaries for the entire company.
There are five territories: 01, 02, 03, 04, and 05.
Systems flowchart
Record description layout for physical salary file
Field Description | Type | Size | COBOL Field-name |
---|---|---|---|
Employee Number | S | 5,0 | EMPLOYEE-NUMBER |
Territory Number | S | 2,0 | TERRITORY-NUMBER |
Annual Salary | P | 5,0 | ANNUAL-SALARY |
Printer spacing chart for salaries by territory report
Write a program to print a population total for each state. The problem definition is shown below. A physical file contains the populations, as shown in the record description layout. The population file is a nonkeyed file with records in no particular order.
Record description layout for physical population file
Field Description | Type | Size | COBOL Field-name |
---|---|---|---|
District Number | S | 2,0 | DISTRICT-NUMBER |
Population | P | 7,0 | POPULATION |
State Number | S | 2,0 | STATE-NUMBER |
County Number | S | 2,0 | COUNTY-NUMBER |
Printer spacing chart for salaries by territory report
Pass-Em State College has student records with the following format:
Record description layout for student file
Field Description | Type | Size | COBOL Field-name |
---|---|---|---|
Student Number | S | 9,0 | STUDENT-NUMBER |
Class | S | 1,0 | CLASS |
School | S | 1,0 | SCHOOL |
GPA | P | 3,2 | GPA |
Credits Earned | P | 3,0 | CREDITS-EARNED |
Assume records are in sequence by class within school.
Codes:
CLASS
1 Freshman
2 Sophomore
3 Junior
4 Senior
SCHOOL
1 Business
2 Liberal Arts
3 Engineering
Print a summary report of the average GPA for each class within each school.
Print each school's statistics on a separate page.
Printer spacing chart for student GPA report
The Bon Voyage Travel Agency would like you to write a program that will print a report showing the average cost of a trip for each booking type. The problem definition is shown below. The data are stored is a nonkeyed physical file, as indicated in the problem definition.
Record description layout for nonkeyed booking file
Field Description | Type | Size | COBOL Field-name |
---|---|---|---|
Client Number | S | 3,0 | CLIENT-NUMBER |
Booking Type | S | 1,0 | BOOKING-TYPE |
Cost of Trip | P | 7,2 | COST-OF-TRIP |
Codes:
Booking Type
1 Cruise
2 Air-Independent
3 Air-Tour
4 Other
Printer spacing chart for average cost report