COBOL在节目结束时报告

时间:2013-02-28 04:52:26

标签: cobol

我正在尝试完成一个我已经开始的程序,但对于我需要做什么以及如何做最后一步感到困惑。说明是:

报告结束时: A.打印处理的人事记录数。 B.搜索部门表失败的记录数。 C.搜索标题表失败的记录数。

我已经完成了除最后一步之外的所有程序。有人可以帮我完成这个程序吗?

enter code here        ENVIRONMENT DIVISION.
   INPUT-OUTPUT SECTION.
   FILE-CONTROL.
       SELECT PERSONNEL-FILE
            ASSIGN TO 'CH12PPPF.DAT'
            ORGANIZATION IS LINE SEQUENTIAL.
       SELECT DEPT-TABLE-FILE
            ASSIGN TO 'CH12PPDT.DAT'
            ORGANIZATION IS LINE SEQUENTIAL.
       SELECT TITLE-TABLE-FILE
           ASSIGN TO 'CH12PPTT.DAT'
           ORGANIZATION IS LINE SEQUENTIAL.
       SELECT PRINT-FILE
           ASSIGN TO 'THORNTONCA4.RPT'
           ORGANIZATION IS LINE SEQUENTIAL.
   DATA DIVISION.
   FILE SECTION.
   FD  PERSONNEL-FILE.
   01  PERSONNEL-REC.
       05  SSNO-IN             PIC 9(9).
       05  NAME-IN             PIC X(20).
       05  SALARY-IN           PIC 9(6).
       05  CAMPUS-CODE-IN      PIC 9.
       05  DEPT-CODE-IN        PIC 99.
       05  TITLE-CODE-IN       PIC 999.
   FD  DEPT-TABLE-FILE.
   01  DEPT-REC.
       05  T-DEPT-NO           PIC 99.
       05  T-DEPT-NAME         PIC X(10).
   FD  TITLE-TABLE-FILE.
   01  TITLE-REC.
       05  T-TITLE-CODE        PIC 999.
       05  T-TITLE-NAME        PIC X(10).
   FD  PRINT-FILE.
   01  PRINT-REC               PIC X(80).
   WORKING-STORAGE SECTION.
   01  STORED-AREAS.
       05  MORE-RECS           PIC X(3)        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(25)
               VALUE SPACES.
       05                                  PIC X(20)
               VALUE 'FINAL 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.


  *****************************************************************
  *  The Campus Table consists of 5 10-position names and will be *
  *    accessed as a direct-referenced table.  EACH_CAMPUS        *
  *    subscriped by the CAMPUS_CODE_IN will provide the name.    *
  *****************************************************************
   01  CAMPUTS-TABLE
         VALUE 'UPSTATE   DOWNSTATE CITY  MELVILLE      HUNTINGTON'.
       05  EACH-CAMPUS
           OCCURS 5 TIMES      PIC X(10).
  *****************************************************************
  * The Dept Table will be accessed by a SEARCH.  Even if the     *
  *    table is entered in Dept No sequence, there would be no    *
  *    real benefit to using a SEARCH ALL since there are only    *
  *    25 entries.                                                *
  *****************************************************************
   01  DEPT-TABLE.
       05  DEPT-ENTRIES OCCURS 25 TIMES INDEXED BY X1.
           10  DEPT-NO         PIC 99.
           10  DEPT-NAME       PIC X(10).
  *****************************************************************
  * The Title Talbe will be accessed by a SEARCH ALL.  To use a   *
  *    binary seach the entries must be in sequence by a key      *
  *    field and the table should be relatively large.            *
  *****************************************************************
   01  TITLE-TABLE.
       05  TITLE-ENTRIES OCCURS 50 TIMES
             ASCENDING KEY IS TITLE-NO INDEXED BY X2.
           10  TITLE-NO        PIC 999.
           10  TITLE-NAME      PIC X(10).
   01  DETAIL-REC.
       05                      PIC X(1) VALUE SPACES.
       05  SSNO-OUT            PIC 999B99B9999.
       05                      PIC X(1) VALUE SPACES.
       05  NAME-OUT            PIC X(20).
       05                      PIC X(1) VALUE SPACES.
       05  SALARY-OUT          PIC $ZZZ,ZZZ.
       05                      PIC X(1) VALUE SPACES.
       05  CAMPUS-OUT          PIC X(10).
       05                      PIC X(1) VALUE SPACES.
       05  DEPT-OUT            PIC X(10).
       05                      PIC X(1) VALUE SPACES.
       05  TITLE-OUT           PIC X(10).
   PROCEDURE DIVISION.
   100-MAIN-MODULE.
       OPEN INPUT  PERSONNEL-FILE
                   DEPT-TABLE-FILE
                   TITLE-TABLE-FILE
            OUTPUT PRINT-FILE
       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 500-HDG-RTN.
       PERFORM 200-LOAD-DEPT-TABLE
       PERFORM 300-LOAD-TITLE-TABLE
       PERFORM UNTIL MORE-RECS = 'NO '
            READ PERSONNEL-FILE
              AT END
                 MOVE 'NO ' TO MORE-RECS
              NOT AT END
                 PERFORM 400-CALC-RTN
            END-READ
       END-PERFORM
       CLOSE PERSONNEL-FILE
             DEPT-TABLE-FILE
             TITLE-TABLE-FILE
             PRINT-FILE
       STOP RUN.
   200-LOAD-DEPT-TABLE.
       PERFORM VARYING X1 FROM 1 BY 1
                UNTIL X1 > 25
          READ DEPT-TABLE-FILE
            AT END DISPLAY 'NOT ENOUGH DEPT TABLE RECORDS'
                STOP RUN
          END-READ
          MOVE DEPT-REC TO DEPT-ENTRIES (X1)
       END-PERFORM.
   300-LOAD-TITLE-TABLE.
       PERFORM VARYING X2 FROM 1 BY 1
                UNTIL X2 > 50
          READ TITLE-TABLE-FILE
            AT END DISPLAY 'NOT ENOUH TITLE TABLE RECORDS'
                STOP RUN
          END-READ
          MOVE TITLE-REC TO TITLE-ENTRIES (X2)
          IF X2 > 1 THEN
              IF TITLE-NO (X2) <= TITLE-NO (X2 - 1)
                 DISPLAY 'TITLE RECORDS ARE NOT IN SEQUENCE'
                 STOP RUN
              END-IF
          END-IF
       END-PERFORM.
   400-CALC-RTN.
       MOVE SPACES TO DETAIL-REC
       MOVE SSNO-IN TO SSNO-OUT
       MOVE NAME-IN TO NAME-OUT
       MOVE SALARY-IN TO SALARY-OUT
       IF CAMPUS-CODE-IN >= 1 AND <= 5
          MOVE EACH-CAMPUS (CAMPUS-CODE-IN) TO CAMPUS-OUT
       END-IF
       SET X1 TO 1
       SEARCH DEPT-ENTRIES
          AT END MOVE 'XXXXXXXXXX' TO DEPT-OUT
          WHEN DEPT-CODE-IN = DEPT-NO (X1)
            MOVE DEPT-NAME (X1) TO DEPT-OUT
       END-SEARCH
       SEARCH ALL TITLE-ENTRIES
          AT END MOVE 'XXXXXXXXXX' TO TITLE-OUT
          WHEN TITLE-NO (X2) = TITLE-CODE-IN
            MOVE TITLE-NAME (X2) TO TITLE-OUT
       END-SEARCH
       WRITE PRINT-REC FROM DETAIL-REC
           AFTER ADVANCING 2 LINES.
   500-HDG-RTN.
       ADD 1 TO WS-PAGE-CT
       MOVE WS-PAGE-CT TO PAGE-OUT
       WRITE PRINT-REC FROM HDR1-OUT
            AFTER ADVANCING PAGE
       MOVE ZEROS TO WS-LINE-CT.

1 个答案:

答案 0 :(得分:2)

你需要:

生成代码以累积最后需要打印的所有值 制作报告最后部分的定义 一旦主输入文件被处理,即在您的第一个PERFORM之后和关闭之前生成报告的最后部分

您应养成在每次IO操作后使用FILE-STATUS检查所有文件状态的习惯,并准确报告何时发生意外情况。

你会发现甚至为索引提供好名字也是值得的,并且尽可能使用88s进行IF或评估,并避免使用这样的“IF CAMPUS-CODE-IN&gt; = 1 AND&lt; = 5”。