Presentation is loading. Please wait.

Presentation is loading. Please wait.

Final Total Lines in COBOL Please be sure you can see the speaker notes - they contain additional information!

Similar presentations


Presentation on theme: "Final Total Lines in COBOL Please be sure you can see the speaker notes - they contain additional information!"— Presentation transcript:

1 Final Total Lines in COBOL Please be sure you can see the speaker notes - they contain additional information!

2 To be able to produce final totals at the bottom of the report, the following coding must be added to your program: First: First: accumulators must be defined be defined and setup in the Working-Storage Section Second: Second: the final total line or lines must be defined and setup in the Working-Storage Section Third: Third: in the processing routine in your program, the accumulators must be added to Fourth: Fourth: there must be a code in the terminate part of your program that moves the contents of the accumulators to the final total line and prints out the final totals. This can either be done in the C- 100-TERMINATE paragraph or a separate paragraph controlled by C-100-TERMINATE (or whatever name is used to define the wrapup or terminate paragraph) Final Total Processing

3 WORKING-STORAGE SECTION. 01 INDICATORZ. 05 EOF-IND PIC XXX VALUE SPACES. 01 ACCUMULATORS. 05 TOTAL-RECORDS-ACC PIC 999 VALUE TOTAL-ON-HAND-ACC PIC 9(6) VALUE TOTAL-ON-ORDER-ACC PIC 9(6) VALUE TOTAL-LINE. 05 FILLER PIC X(16) VALUE " TOTAL RECORDS: ". 05 TOTAL-RECORDS-ACC-TL PIC ZZ9. 05 FILLER PIC X(7) VALUE SPACES. 05 TOTAL-ON-HAND-ACC-TL PIC ZZZ,ZZ9. 05 FILLER PIC XX VALUE SPACES. 05 TOTAL-ON-ORDER-ACC-TL PIC ZZZ,ZZ9. 05 FILLER PIC X(38) VALUE SPACES. WORKING-STORAGE This shows the three accumulators that will be used to gather the totals as the records are processed. When EOF has been reached, the contents of the three accumulators will be moved to the fields on the total line and then the total line will be written. Accumulators need to have an initial value of 0 so that we start adding to nothing. Accumulators are set up in WORKING-STORAGE COBOL RULE: VALUEs are not given to edited fields in WORKING-STORAGE.

4 01 PRINTZ. 05 FILLER PIC X. 05 ITEMNO-PR PIC X(5). 05 FILLER PIC X(3). 05 ITEMNAME-PR PIC X(15). 05 FILLER PIC X(3). 05 ON-HAND-PR PIC ZZ,ZZ9. 05 FILLER PIC X(3). 05 ON-ORDER-PR PIC ZZ,ZZ9. 05 FILLER PIC X(3). 05 REORD-PT-PR PIC ZZ,ZZ9. 05 FILLER PIC X(3). 05 COST-PR PIC ZZZ FILLER PIC X(3). 05 PRICE-PR PIC Z,ZZ FILLER PIC X(3). 05 VENDORID-PR PIC XXX. 05 FILLER PIC X(3). 01 level of FD - PRINTZ ITEMNO-PR(5) ON-HAND-PR(6) REORD-PT-PR(6) PRICE-PR(6) ITEMNAME-PR(15) ON-ORDER-PR(6) COST-PR(6) VENDORID-PR(3) Detail print line - in FILE SECTION

5 ITEMNO-PR(5) ON-HAND-PR(6) REORD-PT-PR(6) PRICE-PR(6) ITEMNAME-PR(15) ON-ORDER-PR(6) COST-PR(6) VENDORID-PR(3) 01 TOTAL-LINE. 05 FILLER PIC X(16) VALUE " TOTAL RECORDS: ". 05 TOTAL-RECORDS-ACC-TL PIC ZZ9. 05 FILLER PIC X(7) VALUE SPACES. 05 TOTAL-ON-HAND-ACC-TL PIC ZZZ,ZZ9. 05 FILLER PIC XX VALUE SPACES. 05 TOTAL-ON-ORDER-ACC-TL PIC ZZZ,ZZ9. 05 FILLER PIC X(38) VALUE SPACES. 01 TOTAL-LINE (set up in WORKING-STORAGE) PRINTZ TOTAL-LINE ^TOTAL^RECORDS:^ TOTAL-ON-HAND-ACC-TL(7) TOTAL-RECORDS-ACC-TL(3) TOTAL-ON-ORDER-ACC-TL This slide lays out the TOTAL-LINE to be compatible with the detail line called PRINTZ.

6 B-200-PROCESS-RECORD-LOOP. MOVE SPACES TO PRINTZ. MOVE ITEMNO TO ITEMNO-PR. MOVE ITEMNAME TO ITEMNAME-PR. MOVE ON-HAND TO ON-HAND-PR. MOVE ON-ORDER TO ON-ORDER-PR. MOVE REORD-PT TO REORD-PT-PR. MOVE COST TO COST-PR. MOVE PRICE TO PRICE-PR. MOVE VENDORID TO VENDORID-PR. ADD 1 TO TOTAL-RECORDS-ACC. ADD ON-HAND TO TOTAL-ON-HAND-ACC. ADD ON-ORDER TO TOTAL-ON-ORDER-ACC WRITE PRINTZ AFTER ADVANCING 1 LINE. READ INVEN-FILE AT END MOVE "YES" TO EOF-IND. 01 ACCUMULATORS. 05 TOTAL-RECORDS-ACC PIC 999 VALUE TOTAL-ON-HAND-ACC PIC 9(6) VALUE TOTAL-ON-ORDER-ACC PIC 9(6) VALUE 0. Part of processing a record is to add to the accumulators. This assures that the information about each record will be included in the accumulators. Processing accumulators Adding to accumulators

7 C-100-TERMINATE. MOVE TOTAL-RECORDS-ACC TO TOTAL-RECORDS-ACC-TL. MOVE TOTAL-ON-HAND-ACC TO TOTAL-ON-HAND-ACC-TL. MOVE TOTAL-ON-ORDER-ACC TO TOTAL-ON-ORDER-ACC-TL. WRITE PRINTZ FROM TOTAL-LINE AFTER ADVANCING 2 LINES. CLOSE INVEN-FILE INVEN-REPORT. 01 ACCUMULATORS. 05 TOTAL-RECORDS-ACC PIC 999 VALUE TOTAL-ON-HAND-ACC PIC 9(6) VALUE TOTAL-ON-ORDER-ACC PIC 9(6) VALUE TOTAL-LINE. 05 FILLER PIC X(16) VALUE " TOTAL RECORDS: ". 05 TOTAL-RECORDS-ACC-TL PIC ZZ9. 05 FILLER PIC X(7) VALUE SPACES. 05 TOTAL-ON-HAND-ACC-TL PIC ZZZ,ZZ9. 05 FILLER PIC XX VALUE SPACES. 05 TOTAL-ON-ORDER-ACC-TL PIC ZZZ,ZZ9. 05 FILLER PIC X(38) VALUE SPACES. Setting up and writing TOTAL-LINE The move statements move the information from the accumulators to the final total line. The final total line is written by moving it to PRINTZ and writing PRINTZ. The from accomplishes the move. Setting up totals on total line

8 Flowchart - final totals - part 1 MAINLINE PERFORM A-100- INITIALIZE PERFORM B-100- PROCESS PERFORM C-100- WRAPUP STOP RUN A-100- INITIALIZE OPEN files End INITIALIZE B-100- PROCESS READ a record EOF Move NO to MORE-RECS Y N Not NO PERFORM B-200- LOOP Y N End PROCESS

9 Flowchart - final totals - part 2 B-200-LOOP Set up line ADD to accumulators WRITE detail line READ a record EOF Move NO to MORE-RECS Y N End LOOP C-100 WRAPUP Move accumulators to total line WRITE total line CLOSE files End WRAPUP

10 Program - part 1 IDENTIFICATION DIVISION. PROGRAM-ID. GRO1. AUTHOR. GROCER. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT INVEN-FILE ASSIGN TO "C:\PCOBWIN\CIS12FST\INVEN.DAT". SELECT INVEN-REPORT ASSIGN TO PRINTER. DATA DIVISION. FILE SECTION. FD INVEN-FILE DATA RECORD IS INVEN-REC. 01 INVEN-REC. 05 ITEMNO PIC X(5). 05 ITEMNAME PIC X(15). 05 ON-HAND PIC 9(5). 05 ON-ORDER PIC 9(5). 05 REORD-PT PIC 9(5). 05 COST PIC 999V PRICE PIC 9(4)V FILLER PIC X(10). 05 VENDORID PIC XXX.

11 Program - part 2 FD INVEN-REPORT DATA RECORD IS PRINTZ. 01 PRINTZ. 05 FILLER PIC X. 05 ITEMNO-PR PIC X(5). 05 FILLER PIC X(3). 05 ITEMNAME-PR PIC X(15). 05 FILLER PIC X(3). 05 ON-HAND-PR PIC ZZ,ZZ9. 05 FILLER PIC X(3). 05 ON-ORDER-PR PIC ZZ,ZZ9. 05 FILLER PIC X(3). 05 REORD-PT-PR PIC ZZ,ZZ9. 05 FILLER PIC X(3). 05 COST-PR PIC ZZZ FILLER PIC X(3). 05 PRICE-PR PIC Z,ZZ FILLER PIC X(3). 05 VENDORID-PR PIC XXX. 05 FILLER PIC X(3).

12 WORKING-STORAGE SECTION. 01 INDICATORZ. 05 EOF-IND PIC XXX VALUE SPACES. 01 ACCUMULATORS. 05 TOTAL-RECORDS-ACC PIC 999 VALUE TOTAL-ON-HAND-ACC PIC 9(6) VALUE TOTAL-ON-ORDER-ACC PIC 9(6) VALUE TOTAL-LINE. 05 FILLER PIC X(16) VALUE " TOTAL RECORDS: ". 05 TOTAL-RECORDS-ACC-TL PIC ZZ9. 05 FILLER PIC X(7) VALUE SPACES. 05 TOTAL-ON-HAND-ACC-TL PIC ZZZ,ZZ9. 05 FILLER PIC XX VALUE SPACES. 05 TOTAL-ON-ORDER-ACC-TL PIC ZZZ,ZZ9. 05 FILLER PIC X(38) VALUE SPACES. Program - part 3

13 Program - part 4 PROCEDURE DIVISION. MAIN-PROGRAM. PERFORM A-100-INITIALIZE. PERFORM B-100-PROCESS-FILE. PERFORM C-100-TERMINATE. STOP RUN. A-100-INITIALIZE. OPEN INPUT INVEN-FILE OUTPUT INVEN-REPORT. B-100-PROCESS-FILE. READ INVEN-FILE AT END MOVE "YES" TO EOF-IND. PERFORM B-200-PROCESS-RECORD-LOOP UNTIL EOF-IND = "YES".

14 Program - part 5 B-200-PROCESS-RECORD-LOOP. MOVE SPACES TO PRINTZ. MOVE ITEMNO TO ITEMNO-PR. MOVE ITEMNAME TO ITEMNAME-PR. MOVE ON-HAND TO ON-HAND-PR. MOVE ON-ORDER TO ON-ORDER-PR. MOVE REORD-PT TO REORD-PT-PR. MOVE COST TO COST-PR. MOVE PRICE TO PRICE-PR. MOVE VENDORID TO VENDORID-PR. ADD 1 TO TOTAL-RECORDS-ACC. ADD ON-HAND TO TOTAL-ON-HAND-ACC. ADD ON-ORDER TO TOTAL-ON-ORDER-ACC WRITE PRINTZ AFTER ADVANCING 1 LINE. READ INVEN-FILE AT END MOVE "YES" TO EOF-IND. C-100-TERMINATE. MOVE TOTAL-RECORDS-ACC TO TOTAL-RECORDS-ACC-TL. MOVE TOTAL-ON-HAND-ACC TO TOTAL-ON-HAND-ACC-TL. MOVE TOTAL-ON-ORDER-ACC TO TOTAL-ON-ORDER-ACC-TL. WRITE PRINTZ FROM TOTAL-LINE AFTER ADVANCING 2 LINES. CLOSE INVEN-FILE INVEN-REPORT.

15 Input data file: 11111TEDDY BEAR ABC 12121DOLL XYZ 12345TRUCK XYZ 22222GOODNIGHT MOON ABC 24242ADVEN PETER RAB ABC 27282LITTLE WOMEN ABC 30303LASSIE COMEHOME ABC 33457BUILDING BLOCKS CRIB XYZ 45678BOUNCE BALL XYZ FD INVEN-FILE DATA RECORD IS INVEN-REC. 01 INVEN-REC. 05 ITEMNO PIC X(5). 05 ITEMNAME PIC X(15). 05 ON-HAND PIC 9(5). 05 ON-ORDER PIC 9(5). 05 REORD-PT PIC 9(5). 05 COST PIC 999V PRICE PIC 9(4)V FILLER PIC X(10). 05 VENDORID PIC XXX. Show input data description and the actual data on the file.

16 FD INVEN-REPORT DATA RECORD IS PRINTZ. 01 PRINTZ. 05 FILLER PIC X. 05 ITEMNO-PR PIC X(5). 05 FILLER PIC X(3). 05 ITEMNAME-PR PIC X(15). 05 FILLER PIC X(3). 05 ON-HAND-PR PIC ZZ,ZZ9. 05 FILLER PIC X(3). 05 ON-ORDER-PR PIC ZZ,ZZ9. 05 FILLER PIC X(3). 05 REORD-PT-PR PIC ZZ,ZZ9. 05 FILLER PIC X(3). 05 COST-PR PIC ZZZ FILLER PIC X(3). 05 PRICE-PR PIC Z,ZZ FILLER PIC X(3). 05 VENDORID-PR PIC XXX. 05 FILLER PIC X(3) TEDDY BEAR ABC DOLL XYZ TRUCK XYZ GOODNIGHT MOON ABC ADVEN PETER RAB ABC LITTLE WOMEN ABC LASSIE COMEHOME ,50.97 ABC BUILDING BLOCKS CRIB ,25.00 XYZ BOUNCE BALL 1, XYZ Detail line and output

17 01 TOTAL-LINE. 05 FILLER PIC X(16) VALUE " TOTAL RECORDS: ". 05 TOTAL-RECORDS-ACC-TL PIC ZZ9. 05 FILLER PIC X(7) VALUE SPACES. 05 TOTAL-ON-HAND-ACC-TL PIC ZZZ,ZZ9. 05 FILLER PIC XX VALUE SPACES. 05 TOTAL-ON-ORDER-ACC-TL PIC ZZZ,ZZ9. 05 FILLER PIC X(38) VALUE SPACES. TOTAL RECORDS: 10 1, TOTAL-LINE Layout of total line and total line itself

18 Input data file: 11111TEDDY BEAR ABC 12121DOLL XYZ 12345TRUCK XYZ 22222GOODNIGHT MOON ABC 24242ADVEN PETER RAB ABC 27282LITTLE WOMEN ABC 30303LASSIE COMEHOME ABC 33457BUILDING BLOCKS CRIB XYZ 45678BOUNCE BALL XYZ Output file: TEDDY BEAR ABC DOLL XYZ TRUCK XYZ GOODNIGHT MOON ABC ADVEN PETER RAB ABC LITTLE WOMEN ABC LASSIE COMEHOME ,50.97 ABC BUILDING BLOCKS CRIB ,25.00 XYZ BOUNCE BALL 1, XYZ TOTAL RECORDS: 10 1, Input file and Output Report


Download ppt "Final Total Lines in COBOL Please be sure you can see the speaker notes - they contain additional information!"

Similar presentations


Ads by Google