Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
232 views
in Technique[技术] by (71.8m points)

file - Finding Highest , Lowest and the Average in a Cobol program

I am creating a program that is reading in a file which consists of companies and their information. It is supposed to read all the records in my file then display the companies with a 3.5 rating or higher with their information, then it is to reject companies with a rating lower that 3.5 and then display the highest quote and the lowest quote and then the average among the companies. I am new to Cobol so I am not sure how to find the highest, lowest and the average. I have coded what I though would work in Module 2012 to find the highest but when I run my program it does not display the information. Any help with this would be greatly appreciated. Thank you

   IDENTIFICATION DIVISION.
   PROGRAM-ID. MOVING-QUOTES.



   ENVIRONMENT DIVISION. 
   INPUT-OUTPUT SECTION.
   FILE-CONTROL.

       SELECT MOVING-QUOTES-FILE ASSIGN TO 'Moving-Quotes.txt'
            ORGANIZATION IS LINE SEQUENTIAL.
       SELECT MOVING-QUOTES-RESULTS-FILE ASSIGN TO "MOVING.TXT"
            ORGANIZATION IS LINE SEQUENTIAL. 

   DATA DIVISION.
   FILE SECTION.
   FD MOVING-QUOTES-FILE.
   01 FS-MOVING-QUOTES-RECORD             PIC X(45).

   FD MOVING-QUOTES-RESULTS-FILE.
   01 MOVING-QUOTES-RESULTS-RECORD        PIC X(80).

   WORKING-STORAGE SECTION.

   01 WS-MOVING-QUOTES-RECORD.
       05 FILLER                           PIC X(2).
       05 MQR-COMPANY-NAME                 PIC X(15).
       05 FILLER                           PIC X(1).
       05 MQR-COMPANY-PHONE                PIC X(13).
       05 FILLER                           PIC X(1).
       05 MQR-MOVING-QUOTE                 PIC 999V99.
       05 FILLER                           PIC X(1).
       05 MQR-NUMBER-ITEMS                 PIC 999.
       05 FILLER                           PIC X(1).
       05 MQR-RATING                       PIC 9V9.

   01 PRT-MOVING-QUOTES-FILE.
       05 FILLER                           PIC X(2).
       05 PRT-MQR-COMPANY-NAME             PIC X(15).
       05 FILLER                           PIC X(1) VALUE SPACES.
       05 PRT-MQR-COMPANY-PHONE            PIC X(13).
       05 FILLER                           PIC X(5).
       05 PRT-MQR-MOVING-QUOTE             PIC $zz99.99.
       05 FILLER                           PIC X(7).
       05 PRT-MQR-NUMBER-ITEMS             PIC 9(3).
       05 FILLER                           PIC X(15).
       05 PRT-MQR-RATING                   PIC 9.9. 

   01 PAGE-TITLE.
       05                  PIC X(22) VALUE SPACES.
       05                  PIC X(40) VALUE  'MOVING COMPANY QUOTES'.
       05                  PIC X(18) VALUE SPACES.
       05 PRT-PAGE-NUM     PIC Z9.

   01 QUOTE-HEADING-1.
       05                               PIC X(7)  VALUE SPACES.
       05                               PIC X(7)  VALUE 'COMPANY'.
       05                               PIC X(9) VALUE SPACES.
       05                               PIC X(5)  VALUE 'PHONE'.
       05                               PIC X(21) VALUE SPACES.
       05                               PIC X(9)  VALUE 'NUMBER OF'.
       05                               PIC X(11) VALUE SPACES.
       05                               PIC X(4)  VALUE 'YELP'.
       05                               PIC X(7). 

   01 QUOTE-HEADING-2.
       05                                  PIC X(8).
       05                                  PIC X(4)  VALUE 'NAME'. 
       05                                  PIC X(11) VALUE SPACES.
       05                                  PIC X(6)  VALUE 'NUMBER'.
       05                                  PIC X(9)  VALUE SPACES.
       05                                  PIC X(5)  VALUE 'QUOTE'.
       05                                  PIC X(7)  VALUE SPACES.
       05                                  PIC X(5)  VALUE 'ITEMS'.
       05                                  PIC X(13) VALUE SPACES.
       05                                  PIC X(6)  VALUE 'RATING'.
       05                                  PIC X(2)  VALUE SPACES.
   01 QUOTE-HEADING-3.          
       05                                  PIC X(6)  VALUE SPACES.
       05                                  PIC X(9)  VALUE  ALL '-'.
       05                                  PIC X(7)  VALUE SPACES.
       05                                  PIC X(8)  VALUE  ALL '-'.
       05                                  PIC X(7)  VALUE SPACES.
       05                                  PIC X(7)  VALUE  ALL '-'.
       05                                  PIC X(5)  VALUE SPACES.
       05                                  PIC X(11) VALUE  ALL '-'.
       05                                  PIC X(7)  VALUE SPACES.
       05                                  PIC X(8)  VALUE  ALL '-'.



   01 WS-SWITCHES-AND-COUNTERS.
       05 WS-EOF                         PIC X       VALUE 'F'.
       05 NUMBER-OF-PAGES                PIC S9(4)   COMP  VALUE 0.
       05 NUMBER-OF-LINES-USED           PIC S9(4)   COMP VALUE 0.
       05 WS-HI-BID                      PIC 999V99 VALUE 0.
       05 WS-LO-BID                      PIC 999V99 VALUE 999.99. 
       05 WS-TOTAL-BID-SUM               PIC 999V99 VALUE 0. 
       05 WS-NUMBER-OF-RECORDS           PIC 9(4)    VALUE 4.
       05 WS-AVERAGE                     PIC 999V99. 

   01 HI-COMPANY-INFO.
       05 FILLER                           PIC X(6) VALUE SPACES.
       05 SAV-HI-MQR-COMPANY-NAME          PIC X(15).
       05 FILLER                           PIC X(2) VALUE SPACES.
       05 SAV-HI-MQR-COMPANY-PHONE         PIC X(13).
       05 FILLER                           PIC X(2) VALUE SPACES.
       05 SAV-HI-MQR-QUOTE                 PIC $ZZ99.99.

   01 LO-COMPANY-INFO.
       05 FILLER                           PIC X(5) VALUE SPACES. 
       05 SAV-LO-MQR-COMPANY-NAME          PIC X(15).
       05 FILLER                           PIC X(2) VALUE SPACES.
       05 SAV-LO-MQR-COMPANY-PHONE         PIC X(13).
       05 FILLER                           PIC X(2) VALUE SPACES. 
       05 SAV-LO-MQR-QUOTE                 PIC $ZZ99.99.

   01 AVG-INFO.
       05                                  PIC X(6) VALUE SPACES.
       05 SAV-AVG                          PIC $ZZ99.99. 

   01 HI-INFO-HD1. 
       05                                  PIC X(8).
       05                                  PIC X(7) VALUE 'HIGH'.
       05                                  PIC X(8).
       05                                  PIC X(5) VALUE 'PHONE'.
       05                                  PIC X(52).

   01 HI-INFO-HD2.
       05                                  PIC X(6).
       05                                  PIC X(7) VALUE 'COMPANY'.
       05                                  PIC X(10).
       05                                  PIC X(6) VALUE 'NUMBER'.
       05                                  PIC X(9).
       05                                  PIC X(5) VALUE 'QUOTE'.
       05                                  PIC X(37).
   01 HI-INFO-HD3.
       05                                  PIC X(5).
       05                                  PIC X(9) VALUE ALL '-'.
       05                                  PIC X(8).
       05                                  PIC X(8) VALUE ALL '-'.
       05                                  PIC X(7).
       05                                  PIC X(7) VALUE ALL '-'.
       05                                  PIC X(36).

   01 LO-INFO-HD1. 
       05                                  PIC X(7).
       05                                  PIC X(3) VALUE 'LOW'.
       05                                  PIC X(13).
       05                                  PIC X(5) VALUE 'PHONE'.
       05                                  PIC X(52). 

   01 LO-INFO-HD2.
       05                                  PIC X(6).
       05                                  PIC X(7) VALUE 'COMPANY'.
       05                                  PIC X(10).
       05                                  PIC X(6) VALUE 'NUMBER'.
       05                                  PIC X(9).
       05                                  PIC X(5) VALUE 'QUOTE'.
       05                                  PIC X(37). 

   01 LO-INFO-HD3.
       05                                  PIC X(5).
       05                                  PIC X(9) VALUE ALL '-'.
       05                                  PIC X(8).
       05                                  PIC X(8) VALUE ALL '-'.
       05                                  PIC X(7).
       05                                  PIC X(7) VALUE ALL '-'.
       05                                  PIC X(36).

   01 AVG-INFO-HD1.
       05                                  PIC X(7).
       05                                  PIC X(7) VALUE 'AVERAGE'.

   01 AVG-INFO-HD2.                       
       05                                  PIC X(6).
       05                                  PIC X(9) VALUE ALL '-'.
       05                                  PIC X(65).

   PROCEDURE DIVISION.
   0000-MAINLINE.
       PERFORM 1000-START-MOVING-QUOTES
       PERFORM 2000-READ-N-PRINT-MQ
            UNTIL WS-EOF = 'T'    
       PERFORM 3000-FINISH-UP
       STOP RUN
       .


  *END OF MAIN BLOCK 

   1000-START-MOVING-QUOTES.
       OPEN INPUT MOVING-QUOTES-FILE
            OUTPUT MOVING-QUOTES-RESULTS-FILE
       PERFORM 8000-READ-MOVING-QUOTES-FILE
       IF WS-EOF NOT = 'T' 
           PERFORM 8020-PRINT-TITLE-AND-HEADINGS.
       .


   8000-READ-MOVING-QUOTES-FILE.
       READ MOVING-QUOTES-FILE 
           AT END MOVE 'T' TO WS-EOF
       end-READ
       MOVE FS-MOVING-QUOTES-RECORD TO 
            WS-MOVING-QUOTES-RECORD 
       .        


   8010-CHECK-LINES.
       ADD 2 TO NUMBER-OF-LINES-USED
       IF NUMBER-OF-LINES-USED > 90 
           PERFORM 8020-PRINT-TITLE-AND-HEADINGS
       .

   8020-PRINT-TITLE-AND-HEADINGS.
       ADD 1 TO NUMBER-OF-PAGES
       MOVE NUMBER-OF-PAGES TO PRT-PAGE-NUM
       MOVE SPACES TO MOVING-QUOTES-RESULTS-RECORD
       MOVE PAGE-TITLE TO MOVING-QUOTES-RESULTS-RECORD 
       WRITE MOVING-QUOTES-RESULTS-RECORD AFTER ADVANCING 3 LINES
       WRITE MOVING-QUOTES-RESULTS-RECORD FROM NUMBER-OF-PAGES
           AFTER ADVANCING 1 LINE          
       WRITE MOVING-QUOTES-RESULTS-RECORD FROM QUOTE-HEADING-1
           AFTER ADVANCING 1 LINE
       WRITE MOVING-QUOTES-RESULTS-RECORD FROM QUOTE-HEADING-2
           AFTER ADVANCING 1 LINE
       WRITE MOVING-QUOTES-RESULTS-RECORD FROM QUOTE-HEADING-3 
           AFTER ADVANCING 1 LINE
       .

   8025-PRINT-HI-HD.
       MOVE SPACES TO MOVING-QUOTES-RESULTS-RECORD
       WRITE MOVING-QUOTES-RESULTS-RECORD FROM HI-INFO-HD1
           AFTER ADVANCING 1 LINE 
       WRITE MOVING-QUOTES-RESULTS-RECORD FROM HI-INFO-HD2
           AFTER ADVANCING 1 LINE
       WRITE MOVING-QUOTES-RESULTS-RECORD FROM HI-INFO-HD3 
           AFTER ADVANCING 1 LINE
       .

   8026-PRINT-LO-HD.
       WRITE MOVING-QUOTES-RESULTS-RECORD FROM LO-INFO-HD1
           AFTER ADVANCING 1 LINE 
       WRITE MOVING-QUOTES-RESULTS-RECORD FROM LO-INFO-HD2
           AFTER ADVANCING 1 LINE 
       WRITE MOVING-QUOTES-RESULTS-RECORD FROM LO-INFO-HD3
           AFTER ADVANCING 1 LINE
       .

   8027-PRINT-AVG-HD.
       WRITE MOVING-QUOTES-RESULTS-RECORD FROM AVG-INFO-HD1
           AFTER ADVANCING 1 LINE 
       WRITE MOVING-QUOTES-RESULTS-RECORD FROM AVG-INFO-HD2
           AFTER ADVANCING 1 LINE
       . 


   2000-READ-N-PRINT-MQ.
  *  PERFORM 8010-CHECK-LINES
       PERFORM 8000-READ-MOVING-QUOTES-FILE
       IF (MQR-RATING >= 3.5) 
           MOVE WS-MOVING-QUOTES-RECORD TO 
           PRT-MOVING-QUOTES-FILE
           PERFORM 2001-PRINT-COMP
           PERFORM 2010-FIND-HI-LO-AVG
       END-IF   


       .

   2001-PRINT-COMP.
       MOVE MQR-COMPANY-NAME TO PRT-MQR-C

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

@Magoo is quite correct, you have not ended the Read so the following lines are only executed at the end-of-file

   MOVE FS-MOVING-QUOTES-RECORD TO
        WS-MOVING-QUOTES-RECORD.

another option is the end-read

8000-READ-MOVING-QUOTES-FILE.
   READ MOVING-QUOTES-FILE
       AT END MOVE 'T' TO WS-EOF
   end-Read
   MOVE FS-MOVING-QUOTES-RECORD TO
        WS-MOVING-QUOTES-RECORD
   .

personally I would move the "Move FS-MOVING" to 2000- or 8010-

2000-READ-N-PRINT-MQ.
     MOVE FS-MOVING-QUOTES-RECORD TO
          WS-MOVING-QUOTES-RECORD
     PERFORM 8010-CHECK-LINES

     ....
8000-READ-MOVING-QUOTES-FILE.
   READ MOVING-QUOTES-FILE
       AT END MOVE 'T' TO WS-EOF
   end-Read
   .

One final point, when you number procedures they should put them in numeric sequence


Some more issues in 2000- the perform 8000- should be at the end of the procedure

Currently:

  2000-READ-N-PRINT-MQ.
  *  PERFORM 8010-CHECK-LINES
       PERFORM 8000-READ-MOVING-QUOTES-FILE
       IF (MQR-RATING >= 3.5) 
           MOVE WS-MOVING-QUOTES-RECORD TO 
           PRT-MOVING-QUOTES-FILE
           PERFORM 2001-PRINT-COMP
           PERFORM 2010-FIND-HI-LO-AVG
       END-IF   

Should be:

  2000-READ-N-PRINT-MQ.
  *  PERFORM 8010-CHECK-LINES
       IF (MQR-RATING >= 3.5) 
           MOVE WS-MOVING-QUOTES-RECORD TO 
           PRT-MOVING-QUOTES-FILE
           PERFORM 2001-PRINT-COMP
           PERFORM 2010-FIND-HI-LO-AVG
       END-IF   
       PERFORM 8000-READ-MOVING-QUOTES-FILE

also in 2012- why are you doing a write, surely this should be done at the end (section 3000-).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...