Download presentation
Presentation is loading. Please wait.
1
Minor, Intermediate and Major Breaks
Please use speaker notes for additional information! These slides will go over the logic for minor, intermediate and major breaks in a program.
2
Input data: Input data for major.cbl 0110121234HOE 01201899
RAKE TROWEL HAND HOE LILY TULIP PANSY PETUNIA DOGWOOD CHERRY WHITE PINE BLACK PINE MAPLE OAK This is the input data for the program called major.cbl that is available at the site. It is the one that was also discussed in class. DIV BR DEPT
3
Report produced by major.cbl
04/11/ INVENTORY REPORT PAGE 1 DIV BR DEPT ITEM # ITEM NAME ON HAND PRICE INVEN VALUE HOE $ $227.88 RAKE $ $398.75 TOTALS FOR DEPT: $626.63 TROWEL $ $119.80 HAND HOE $ $111.86 TOTALS FOR DEPT: $231.66 TOTALS FOR BRANCH: $858.29 LILY $ $99.50 TULIP $ $224.25 TOTALS FOR DEPT: $323.75 TOTALS FOR BRANCH: $323.75 PANSY $ $670.88 PETUNIA $ $499.00 TOTALS FOR DEPT: $1,169.88 TOTALS FOR BRANCH: $1,169.88 TOTALS FOR DIVISION: $2,351.92 DOGWOOD $ $1,009.90 CHERRY $ $1,200.00 TOTALS FOR DEPT: $2,209.90 TOTALS FOR BRANCH: $2,209.90 WHITE PINE $ $675.00 BLACK PINE $ $2,000.00 TOTALS FOR DEPT: $2,675.00 TOTALS FOR BRANCH: $2,675.00 MAPLE $ $600.00 OAK $ $891.00 TOTALS FOR DEPT: $1,491.00 TOTALS FOR BRANCH: $1,491.00 TOTALS FOR DIVISION: $6,375.90 FINAL TOTAL: $8,727.82 This is the output report from the program major.cbl.
4
The first seven input records: 0110121234HOE 01201899
First 7 records: The first seven input records: HOE RAKE TROWEL HAND HOE LILY TULIP PANSY Note that when the dept changes from 12 to 15, a total is written for dept 12 before dept 15 is processed. 04/11/ INVENTORY REPORT PAGE 1 DIV BR DEPT ITEM # ITEM NAME ON HAND PRICE INVEN VALUE HOE $ $227.88 RAKE $ $398.75 TOTALS FOR DEPT: $626.63 TROWEL $ $119.80 HAND HOE $ $111.86 TOTALS FOR DEPT: $231.66 TOTALS FOR BRANCH: $858.29 LILY $ $99.50 TULIP $ $224.25 TOTALS FOR DEPT: $323.75 TOTALS FOR BRANCH: $323.75 PANSY $ $670.88 Note when the BR changes from 10 to 20, I need to write a dept total for the last dept and then a branch total for the br before I process the first record in br 20. This shows the first seven records and the resulting report. Notice then when the dept breaks, I print a dept total before processing the record that caused the break and when the br changes, I print a branch total before processing the record that caused the break.
5
B-320- B-100- PROCESS MAINLINE A A-100- INITIALIZE READ 1ST RECORD
AT END NO TO MORE-RECS B MAJOR-ROUT B-100- PROCESS DIV TO DIV-HOLD BR TO BR-HOLD DEPT TO DEPT-HOLD C-100- WRAPUP B-340- FINAL-ROUT STOP RUN B-200- LOOP Y END B-100 MORE-RECS NOT = NO A-100-INITIALIZE OPEN FILES N B-310- MINOR-ROUT This is the logic flowchart - page 1. Note that with the first or initializing read I can do special processing because this read only applies to the first record. The special processing that I do is to move the data from the first record to the hold areas. Note also that when I am done with the processing of the B-200-LOOP which happens when I have hit EOF, I perform the MINOR-ROUT for the last department so it will have a total, INTER-ROUT for the last branch so it will have a total, MAJOR-ROUT for the last division so it will have a total and then finally the FINAL-ROUT to get a total for the entire data file. PROCESS DATE NOTE: DIV is the major break field, BR is the intermediate break field, and DEPT is the minor break field in this example. The move to hold should move whatever is the major break field, the intermediate break field and the minor break field. B-320- INTER-ROUT END A-100 A
6
B B-200-LOOP N DIV NOT = DIV-HOLD Y N Y BR NOT = BR-HOLD B-310-
MINOR-ROUT B-310- MINOR-ROUT B-230- INTER-ROUT N DEPT NOT = DEPT-HOLD Y B-230- INTER-ROUT B-240- MAJOR-ROUT B-310- MINOR-ROUT This is the logic flowchart - page 2. Note that I check for the highest level of break first because I am making the assumption that if the division chances, the branch and department also change. If this is not a valid assumption, I would need to code different logic. If the division breaks, I want to process the total for the last department within the division (MINOR-ROUT), the last branch within the division (INTER-ROUT) and the division itself (MAJOR-ROUT). If the branch breaks, I want to process the total for the last department within the division (MINOR-ROUT) and then the branch itself (INTER-ROUT). If the department breaks, I want to process the total for the department only (MINOR-ROUT). If no break happens I do nothing in this IF. I simply fall through to the B which branches to the next page. B
7
B B-300-DETAIL B-300- DETAIL N Need header? Y B-400- HDR-ROUT READ
RECORD AT END NO TO MORE-RECS Set up detail line END B-200 WRITE LINE Add to MINOR-TOTAL INTER-TOTAL MAJOR-TOTAL FINAL-TOTAL This is the logic flowchart - page 3. If no break happened, I fall through and process the detail record and read another record. If a break happened, once I have printed the totals, I fall through to process the detail record that caused the break and then read another record. In the detail routine, I write headers if needed, set up the detail line including any calculations that need to be done, write the detail line and then add to the accumulators. If there are multiple totals at each level, I will add to all of the accumulators here. END B-300
8
RESET: RESET: RESET: RESET: RESET: RESET:
B-310-MINOR- ROUT B-320-FINAL ROUT B-320-INTER- ROUT B-330-MAJOR- ROUT Set up minor total line Set up final total line Set up intermed total line Set up major total line WRITE MINOR TOTAL LINE WRITE FINAL TOTAL LINE WRITE INTER TOTAL LINE WRITE MAJOR TOTAL LINE END B-320 RESET: DEPT TO DEPT-HOLD RESET: BR TO BR-HOLD RESET: DIVTO DIV-HOLD RESET: MINOR-TOTAL = 0 RESET: INTER-TOTAL = 0 RESET: MAJOR-TOTAL = 0 END B-310 This is the logic flowchart - page 4. The total routines are all very similar. I set up the total line, write the total line and then reset the hold area that goes with that line and reset the totals that go with that line. In other words, for a minor break I am resetting dept hold and the dept or minor totals, for the inter break I am resetting the br hold and the inter or branch totals and for the major break I am resetting the div hold and the div or major totals. END B-320 END B-330
9
B-400- HDR-ROUT C-100-WRAPUP Set up page CLOSE FILES and line headers
WRITE PAGE & LINE HEADERS END C-100 Add to page # and reset line count END B-400 This is the logic flowchart - page 5. It simply handles writing headers and the wrapup which closes the files.
10
B-100-PROCESS. B-320- A B-100- PROCESS READ 1ST RECORD NO TO MORE-RECS
AT END NO TO MORE-RECS B MAJOR-ROUT DIV TO DIV-HOLD BR TO BR-HOLD DEPT TO DEPT-HOLD B-340- FINAL-ROUT END B-100 B-200- LOOP Y MORE-RECS NOT = NO B-100-PROCESS. READ INPUT-FILE AT END MOVE "NO " TO MORE-RECS. MOVE DIV TO HOLD-DIV. MOVE BRANCH TO HOLD-BRANCH. MOVE DEPT TO HOLD-DEPT. PERFORM B-200-LOOP UNTIL MORE-RECS = "NO ". PERFORM B-310-MINOR-ROUT. PERFORM B-320-INTER-ROUT. PERFORM B-330-MAJOR-ROUT. PERFORM B-340-FINAL-ROUT. N B-310- MINOR-ROUT This shows the logic flowchart and code for B-100-PROCESS. Remember the logic flowchart is generic except for the references to DIV, BR and DEPT while the code is for a specific problem. B-320- INTER-ROUT A
11
B-200-LOOP. B-200-LOOP N DIV NOT = DIV-HOLD Y N Y BR NOT = BR-HOLD
MINOR-ROUT B-310- MINOR-ROUT B-230- INTER-ROUT N DEPT NOT = DEPT-HOLD Y B-230- INTER-ROUT B-240- MAJOR-ROUT B-310- MINOR-ROUT B-200-LOOP. IF DIV NOT = HOLD-DIV PERFORM B-310-MINOR-ROUT PERFORM B-320-INTER-ROUT PERFORM B-330-MAJOR-ROUT PERFORM U-000-BLANK-LINE ELSE IF BRANCH NOT = HOLD-BRANCH IF DEPT NOT = HOLD-DEPT PERFORM U-000-BLANK-LINE. This slide shows the beginning of the B-200-LOOP which checks for breaks and performs the appropriate total routines. The B-200-LOOP is continued on the next slide. B
12
B B-300- DETAIL READ RECORD NO TO MORE-RECS END B-200
AT END NO TO MORE-RECS END B-200 PERFORM B-300-DETAIL. READ INPUT-FILE AT END MOVE "NO " TO MORE-RECS. This is the end of the B-200-LOOP
13
B-300-DETAIL N Need header? Y B-400- HDR-ROUT Set up detail line WRITE
IF LINE-CT > 50 OR PAGE-NO = 1 PERFORM B-400-HDR-ROUT. MOVE SPACES TO PRINTZ. MOVE DIV TO DIV-PR. MOVE BRANCH TO BRANCH-PR. MOVE DEPT TO DEPT-PR. MOVE ITEM-NO TO ITEM-NO-PR. MOVE ITEM-NAME TO ITEM-NAME-PR. MOVE ON-HAND TO ON-HAND-PR. MOVE PRICE TO PRICE-PR. MULTIPLY ON-HAND BY PRICE GIVING INV-VALUE-WS. MOVE INV-VALUE-WS TO INV-VALUE-PR. WRITE PRINTZ AFTER ADVANCING 1 LINES. ADD 1 TO LINE-CT. ADD ON-HAND TO MINOR-ONHAND-ACC. ADD ON-HAND TO INTER-ONHAND-ACC. ADD ON-HAND TO MAJOR-ONHAND-ACC ADD ON-HAND TO FINAL-ONHAND-ACC. ADD INV-VALUE-WS TO MINOR-VALUE-ACC. ADD INV-VALUE-WS TO INTER-VALUE-ACC. ADD INV-VALUE-WS TO MAJOR-VALUE-ACC. ADD INV-VALUE-WS TO FINAL-VALUE-ACC. N Need header? Y B-400- HDR-ROUT Set up detail line WRITE LINE Add to MINOR-TOTAL INTER-TOTAL MAJOR-TOTAL FINAL-TOTAL This slide shows the detail routine. END B-300
14
MOVE HOLD-DEPT TO DEPT-ML.
B-310-MINOR- ROUT Set up minor total line WRITE MINOR TOTAL LINE B-310-MINOR-ROUT. MOVE HOLD-DEPT TO DEPT-ML. MOVE MINOR-ONHAND-ACC TO MINOR-ONHAND-ACC-ML. MOVE MINOR-VALUE-ACC TO MINOR-VALUE-ACC-ML. WRITE PRINTZ FROM MINOR-TOTAL-LINE AFTER ADVANCING 2 LINES. MOVE DEPT TO HOLD-DEPT. MOVE 0 TO MINOR-ONHAND-ACC. MOVE 0 TO MINOR-VALUE-ACC. ADD 2 TO LINE-CT. RESET: DEPT TO DEPT-HOLD RESET: MINOR-TOTAL = 0 END B-310 This slide shows the minor routine.
15
MOVE HOLD-BRANCH TO BRANCH-IL.
B-320-INTER- ROUT Set up intermed total line WRITE INTER TOTAL LINE B-320-INTER-ROUT. MOVE HOLD-BRANCH TO BRANCH-IL. MOVE INTER-ONHAND-ACC TO INTER-ONHAND-ACC-IL. MOVE INTER-VALUE-ACC TO INTER-VALUE-ACC-IL. WRITE PRINTZ FROM INTER-TOTAL-LINE AFTER ADVANCING 1 LINES. MOVE SPACES TO PRINTZ. MOVE BRANCH TO HOLD-BRANCH. MOVE 0 TO INTER-ONHAND-ACC. MOVE 0 TO INTER-VALUE-ACC. ADD 1 TO LINE-CT. RESET: BR TO BR-HOLD RESET: INTER-TOTAL = 0 This is the intermediate routine. END B-320
16
MOVE HOLD-DIV TO DIV-MJL.
B-330-MAJOR- ROUT Set up major total line B-330-MAJOR-ROUT. MOVE HOLD-DIV TO DIV-MJL. MOVE MAJOR-ONHAND-ACC TO MAJOR-ONHAND-ACC-MJL. MOVE MAJOR-VALUE-ACC TO MAJOR-VALUE-ACC-MJL. WRITE PRINTZ FROM MAJOR-TOTAL-LINE AFTER ADVANCING 1 LINES. MOVE DIV TO HOLD-DIV. MOVE 0 TO MAJOR-ONHAND-ACC. MOVE 0 TO MAJOR-VALUE-ACC. ADD 1 TO LINE-CT. WRITE MAJOR TOTAL LINE RESET: DIVTO DIV-HOLD RESET: MAJOR-TOTAL = 0 This is the major routine. END B-330
17
MOVE FINAL-ONHAND-ACC TO FINAL-ONHAND-ACC-FL.
B-320-FINAL ROUT Set up final total line B-340-FINAL-ROUT. MOVE FINAL-ONHAND-ACC TO FINAL-ONHAND-ACC-FL. MOVE FINAL-VALUE-ACC TO FINAL-VALUE-ACC-FL. WRITE PRINTZ FROM FINAL-TOTAL-LINE AFTER ADVANCING 1 LINES. WRITE FINAL TOTAL LINE END B-320 This is the final routine.
18
B-400-HDR-ROUT. B-400- HDR-ROUT MOVE PAGE-NO TO PAGE-NO-HDR.
WRITE PRINTZ FROM PAGE-HDR AFTER ADVANCING PAGE. WRITE PRINTZ FROM COLUMN-HDR AFTER ADVANCING 2 LINES. PERFORM U-000-BLANK-LINE. ADD 1 TO PAGE-NO. MOVE 4 TO LINE-CT. Set up page and line headers WRITE PAGE & LINE HEADERS Add to page # and reset line count END B-400 C-100-WRAPUP C-100-WRAPUP. CLOSE INPUT-FILE PRINT-FILE. This is the header routine and the wrapup routine. CLOSE FILES END C-100
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.