COBOL同时排序和合并

时间:2011-11-21 22:35:25

标签: cobol

我正在接受一项非常困难的工作。我要对两个填充了股票数据的txt文件进行排序和合并。然后我提示用户输入一年,主记录将打印该年内的记录。谁能帮帮我吗。这就是我现在拥有的。

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

       SELECT STOCK-REPORT-A ASSIGN TO 'PR3AF11.TXT'.

       SELECT STOCK-REPORT-B ASSIGN TO 'PR3BF11.TXT'.

       SELECT MERGE-FILE ASSIGN TO 'WORK.TMP'.

       SELECT MASTER-STOCK-REPORT ASSIGN TO 'MASTERSTOCKREPORT.TXT'.

   DATA DIVISION.
   FILE SECTION.

   FD  STOCK-REPORT-A.
   01  REPORTA-REC.
       05  A-InvestorID             PIC X(2).
       05  A-InvestorName           PIC X(5).
       05  A-InvestorRating         PIC X.

   FD  STOCK-REPORT-B.
   01  REPORTB-REC.
       05  B-InvestorID             PIC X(2).
       05  B-InvestorName           PIC X(5).
       05  B-InvestorRating         PIC X.

   SD  MERGE-FILE.
   01  MERGE-REC.
       05  M-InvestorID             PIC X(2).
       05  M-InvestorName           PIC X(5).
       05  M-InvestorRating         PIC X.

   SCREEN SECTION.
   01  TITLE SCREEN.
       05  BLANK SCREEN
           FOREGROUND-COLOR BLACK
           BACKGROUND-COLOR WHITE.
       05  LINE 4 COLUMN 15
           VALUE "STOCKS REPORT GENERATOR"
   01  YEAR-QUESTION-SCREEN.
       05  YEAR-ANSWERS.
           10  LINE 7 COLUMN 10
               VALUE "What year would you like to search for?".
           10  LINE 9 COLUMN 15
               VALUE "2005".
           10  LINE 9 COLUMN 15
               VALUE "2006".
           10  LINE 9 COLUMN 15
               VALUE "2007".
           10  LINE 9 COLUMN 15
               VALUE "2008".
           10  LINE 9 COLUMN 15
               VALUE "2009".
           10  LINE 9 COLUMN 15
               VALUE "2010".
           10  LINE 9 COLUMN 15
               VALUE "2011".

   FD MASTER-STOCK-REPORT.
   01 MASTER-REC                    PIC X(122).

   PROCEDURE DIVISION.
   100-MAIN.
   BEGIN.
       MERGE MERGE-FILE
           ON ASCENDING KEY M-InvestorID
           USING STOCK-REPORT-A
               STOCK-REPORT-B
           GIVING MASTER-STOCK-REPORT.
       STOP RUN.

3 个答案:

答案 0 :(得分:1)

我更喜欢在DFSORT中通过JCL进行排序和合并,然后将该文件输入到COBOL程序,该程序接受用户输入并提供必要的输出。内部程序的排序和合并比外面的要慢,当然显然......

答案 1 :(得分:0)

以下是有关如何排序和合并的示例,只需将其作为两步操作即可。

http://www.csis.ul.ie/cobol/examples/default.htm#Sort

答案 2 :(得分:0)

您无需对进行排序。您可以将两个文件一起排序,在SORT动词的USING短语上指定两个输入文件。

如果您不确定这会给您正确的结果,您可以尝试SORT,SORT,MERGE,然后将输出文件与上面的内容进行比较。或者坐下来用一张纸和一支铅笔来完成它。