Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need to modify the program to print the total amount of all purchases for all

ID: 3538043 • Letter: I

Question

I need to modify the program to print the total amount of all purchases for all customers at the end of the report. That is, the sum total of all purchases. The sum should be $54040.40.

I have already written the code that created a purchase report of customers and their amount of purchase.

Output should look like this:

                                        PURCHASE REPORT     06/23/2013 PAGE 1

          CUSTOMER NO   CUSTOMER NAME             AMOUNT OF PURCHASE
  
             12345      CHARLES NEWTON,INC.                            $       315.00

             23456      HARWOOD ASSOCIATES                           $   51879.75

             34567      LEMON AUTOMOTIVE                                 $    9500.00

             54321      BISTRO BROTHERS                                    $    1345.65
     
        
           TOTAL AMOUT OF PURCHASES IS:                            $ 54040.40


==========================

       IDENTIFICATION DIVISION.
       PROGRAM-ID. CH6PPB.
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT PURCHASE-TRANS ASSIGN TO 'C:CHAPTER6CH6PPB.DAT'
               ORGANIZATION IS LINE SEQUENTIAL.
           SELECT PURCHASE-REPORT ASSIGN TO 'C:CHAPTER6CH6PPB.RPT'
               ORGANIZATION IS LINE SEQUENTIAL.
       DATA DIVISION.
       FILE SECTION.
       FD PURCHASE-TRANS
           RECORD CONTAINS 32 CHARACTERS.
       01 TRANS-REC-IN.
           05 CUST-NO-IN                      PIC X(5).
           05 CUST-NAME-IN                    PIC X(20).
           05 AMT-OF-PUR-IN                   PIC 9(5)V99.
       FD PURCHASE-REPORT
           RECORD CONTAINS 80 CHARACTERS.
       01 PRINT-REC                           PIC X(80).
       WORKING-STORAGE SECTION.
       01 WORK-AREAS.
           05 ARE-THERE-MORE-RECORDS          PIC XXX
                  VALUE 'YES'.
           05 WS-DATE.
               10 WS-YEAR                     PIC 9999.
               10 WS-MONTH                    PIC 99.
               10 WS-DAY                      PIC 99.
           05 WS-PAGE-CT                      PIC 99
                  VALUE ZERO.
           05 WS-LINE-CT                      PIC 99
                  VALUE ZERO.
       01 HDR1-OUT.
           05                                  PIC X(40)
                  VALUE SPACES.
           05                                  PIC X(20)
                  VALUE 'PURCHASE REPORT'.
           05 DATE-OUT.
               10 MONTH-OUT                   PIC 99.
               10                              PIC X
                  VALUE '/'.
               10 DAY-OUT                     PIC 99.
               10                              PIC X
                  VALUE '/'.
               10 YEAR-OUT                    PIC 9999.
           05                                  PIC X(2)
                  VALUE SPACES.
           05                                  PIC X(5)
                  VALUE 'PAGE'.
           05 PAGE-OUT                        PIC Z9.
       01 HDR2-OUT.
           05                                  PIC X(10)
                  VALUE SPACES.
           05                                  PIC X(27)
                  VALUE 'CUSTOMER NO   CUSTOMER NAME'.
           05                                  PIC X(13)
                  VALUE SPACES.
           05                                  PIC X(18)
                  VALUE 'AMOUNT OF PURCHASE'.
       01 DETAIL-REC-OUT.
           05                                  PIC X(13)
                  VALUE SPACES.
           05 CUST-NO-OUT                     PIC X(5).
           05                                  PIC X(6)
                  VALUE SPACES.
           05 CUST-NAME-OUT                   PIC X(20).
           05                                  PIC X(11)
                  VALUE SPACES.
           05 AMT-OF-PUR-OUT                  PIC Z(5).99.
       PROCEDURE DIVISION.
      ****************************************************
      *     All program logic is controlled by           *
      *              100-MAIN-MODULE                     *
      ****************************************************
       100-MAIN-MODULE.
           OPEN INPUT PURCHASE-TRANS
                OUTPUT PURCHASE-REPORT
           MOVE FUNCTION CURRENT-DATE TO WS-DATE
           MOVE WS-MONTH TO MONTH-OUT
           MOVE WS-DAY TO DAY-OUT
           MOVE WS-YEAR TO YEAR-OUT
           PERFORM 200-HDG-RTN.
           PERFORM UNTIL ARE-THERE-MORE-RECORDS = 'NO '
               READ PURCHASE-TRANS
                    AT END
                       MOVE 'NO ' TO ARE-THERE-MORE-RECORDS
                    NOT AT END
                       PERFORM 300-REPORT-RTN
               END-READ
           END-PERFORM
           CLOSE PURCHASE-TRANS
                 PURCHASE-REPORT
           STOP RUN.
      *******************************************************
      *   200-HDG-RTN is executed once from the main module *
      *        and then again after 25 detail lines print   *
      *******************************************************
       200-HDG-RTN.
           ADD 1 TO WS-PAGE-CT
           MOVE WS-PAGE-CT TO PAGE-OUT
           WRITE PRINT-REC FROM HDR1-OUT
                AFTER ADVANCING PAGE
           WRITE PRINT-REC FROM HDR2-OUT
                AFTER ADVANCING 2 LINES
           MOVE ZEROS TO WS-LINE-CT.
      *******************************************************
      *    300-REPORT-RTN is executed from the main module *
      *       until all input records have been processed   *
      *******************************************************
       300-REPORT-RTN.
           IF WS-LINE-CT >= 25
               PERFORM 200-HDG-RTN
           END-IF
           MOVE SPACES TO DETAIL-REC-OUT
           MOVE CUST-NO-IN TO CUST-NO-OUT
           MOVE CUST-NAME-IN TO CUST-NAME-OUT
           MOVE AMT-OF-PUR-IN TO AMT-OF-PUR-OUT
           WRITE PRINT-REC FROM DETAIL-REC-OUT
               AFTER ADVANCING 2 LINES
           ADD 1 TO WS-LINE-CT.

Supporting documentation:

https://www.dropbox.com/s/6rrf4gapkdnvuaq/CH6PPB.CBL

https://www.dropbox.com/s/lnrgia52ygyq7xd/CH6PPB.DAT

Explanation / Answer

You need to:

Produce code to accumulate all the values you need to print at the end Produce definition(s) of the final part of the report Produce the final part of report once the main input file has been processed, ie after your first PERFORM and before the CLOSE

You should get into the habit of checking all file statuses after each IO operation, using FILE-STATUS, and accurately report when something unexpected happens.

You'll find it worthwhile to give good names even to indexes, and use 88s wherever possible for IF or EVALUATE and avoid using things like this "IF CAMPUS-CODE-IN >= 1 AND <= 5".


down vote
accepted

You need to:

Produce code to accumulate all the values you need to print at the end Produce definition(s) of the final part of the report Produce the final part of report once the main input file has been processed, ie after your first PERFORM and before the CLOSE

You should get into the habit of checking all file statuses after each IO operation, using FILE-STATUS, and accurately report when something unexpected happens.

You'll find it worthwhile to give good names even to indexes, and use 88s wherever possible for IF or EVALUATE and avoid using things like this "IF CAMPUS-CODE-IN >= 1 AND <= 5".