如何使用两个VSAM文件中的数据打印报告(循环问题)

时间:2019-04-23 19:15:48

标签: cobol mainframe vsam

我有一个主文件,对此主文件中的一条记录在明细文件中将有多条记录。

例如:主文件中的一条记录可能在详细文件中有20条记录。我必须将主记录与详细记录的记录计数作为报告进行匹配。

更详细的形式的要求:

  

根据检查主文件和相应的明细文件中的信息,编写一个在基本报告中提供以下信息的程序。

     

要求1:对于主数据库上的每个不同的银行代码,报告遇到的每个支票状态以及该状态的支票数量。例如,银行代码BC有45张未结支票。

     

需求2:对于每个银行代码的支票状态(未清,作废,已付款等),请报告与这些状态相对应的详细主记录的数量。例如,BC银行可能只有1张未结支票,相当于明细文件上的45条记录。

     

您应该能够通过针对支票母版的1次传递来完成上述操作。

我编写了用于执行上述操作的程序,但是我的程序正在循环并且不存在主文件结尾,并且明细文件中的记录计数不匹配。请帮助我解决循环以获取所需的输出而且我不知道如何编写要求2。

   FILE-CONTROL.
       SELECT SIR-MASTER-FILE              ASSIGN TO VXSIRCKF
           ORGANIZATION IS INDEXED
           ACCESS MODE IS DYNAMIC
           RECORD KEY IS SIRM-KEY
           FILE STATUS IS SIRM-FILE-STATUS.

       SELECT SIR-DETAIL-FILE              ASSIGN TO VXSIRDEF
           ORGANIZATION IS INDEXED
           ACCESS MODE  IS DYNAMIC
           RECORD KEY   IS SIRD-KEY
           FILE STATUS  IS SIRD-FILE-STATUS.

   DATA DIVISION.
   FILE SECTION.
   FD  SIR-MASTER-FILE.
   01  SIR-MASTER-REC.
       02 SIRM-KEY.
           03  SIRM-CLIENT                 PIC X(02).
           03  SIRM-PLAN                   PIC X(02).
           03  SIRM-REGION                 PIC X(02).
           03  SIRM-BANK-CODE              PIC X(05).
           03  SIRM-CK-ACH-NBR             PIC 9(10).
           03  SIRM-RECORD-NBR             PIC 9(05).
           03  SIRM-SEQUENCE-NBR           PIC 9(02).
       02  SIRM-KEY2                       PIC X(41).
       02  SIRM-KEY3-4.
           03  SIRM-KEY3.
               05  SIRM-RECIP-CLM          PIC X(20).
               05  SIRM-KEY4               PIC X(35).
       02  SIRM-LRECL                      PIC 9(04).
       02  SIRM-DATA.
           03  FILLER                      PIC X(01)
           OCCURS 374 TO 3722 DEPENDING ON SIRM-LRECL.
   COPY VXSIRHDR.

   FD  SIR-DETAIL-FILE.
   01  SIR-DETAIL-REC.
       02  SIRD-KEY.
           03  SIRD-BANK-CODE              PIC X(05).
           03  SIRD-CHECK-NBR              PIC 9(10).
           03  SIRD-CLAIM-NBR              PIC X(25).
           03  SIRD-SEQ-NBR                PIC 9(07).
       02  SIRD-DATE-MOVED                 PIC 9(08).
       02  SIRD-LRECL                      PIC 9(04).
       02  SIRD-DATA.
           03  FILLER                      PIC X(01)
           OCCURS 1 TO 2330 DEPENDING ON SIRD-LRECL.

   WORKING-STORAGE SECTION.

   01  WS-FILE-STATUS.
       05  SIRM-FILE-STATUS                PIC X(02).
       05  SIRD-FILE-STATUS                PIC X(02).
   01  WS-WORK-AREA.
       05  ABEND-RESULT                    PIC 9(01).
       05  ZERO-VAR                        PIC 9(01) VALUE 0.

   01  EOF-SIRM-SW                         PIC X(01) VALUE 'N'.
       88  EOF-SIRM                        VALUE 'Y'.
   01  EOF-SIRD-SW                         PIC X(01) VALUE 'N'.
       88  EOF-SIRD                        VALUE 'Y'.

   01  WS-TABLE.
       02  BANK-INFO                     OCCURS 500
                                           INDEXED BY B-IDX.
           03  WS-BANK-CODES               PIC X(05).
       02  STATUS-INFO                    OCCURS 500
                                          INDEXED BY S-IDX.
           03  WS-STATUS-CODES               PIC X(3).

       02 COUNTER                          PIC 9(5). 

   01 HEADING-LINE1.
      05 FILLER          PIC X(20)  VALUE SPACES.
      05 FILLER         PIC X(36) VALUE 
                        'CHECK MASTER VS DETAIL COUNT REPORT '.
   01 DESIGN.
      05 FILLER          PIC X(20)  VALUE SPACES.
      05 FILLER         PIC X(36) VALUE
                        '************************************'.

   01 HEADING-LINE2.

      05 FILLER                 PIC X(5)  VALUE SPACES.
      05 FILLER                 PIC X(9)  VALUE 'BANK CODE'.
      05 FILLER                 PIC X(1)  VALUE SPACES.
      05 FILLER                 PIC X(12) VALUE 'CHECK STATUS'.
      05 FILLER                 PIC X(2)  VALUE SPACES.
      05 FILLER                 PIC X(11) VALUE 'STATUS CODE'.
      05 FILLER                 PIC X(2)  VALUE SPACES.
      05 FILLER             PIC X(20) VALUE 'DETAIL NO OF RECORDS'.

   01 DETAIL-LINE.
      05 FILLER                       PIC X(5)  VALUE SPACES.
      05 DET-BANK-CODE                PIC X(05).
      05 FILLER                       PIC X(5)  VALUE SPACES.
      05 DET-CHK-NBR                  PIC 9(10).
      05 FILLER                       PIC X(5)  VALUE SPACES.
      05 DET-STATUS-CODE                   PIC X(3).
      05 FILLER                       PIC X(10)  VALUE SPACES.
      05 DET-DETAIL-COUNT            PIC 9(5).

   COPY VXSIRDTL.

   PROCEDURE DIVISION.
       PERFORM INTALIZATION
       PERFORM OPEN-DETAIL
       PERFORM PRINT
       PERFORM INIT
       PERFORM TERMINATION
       GOBACK.

   INTALIZATION.
       OPEN INPUT SIR-MASTER-FILE
       IF SIRM-FILE-STATUS IS NOT EQUAL TO '00'
       THEN
           GO TO ERROR-EXIT
       END-IF.

   OPEN-DETAIL.
       OPEN INPUT SIR-DETAIL-FILE
       IF SIRD-FILE-STATUS IS NOT EQUAL TO '00'
       THEN
           GO TO ERROR-EXIT
       END-IF.

   PRINT.
       DISPLAY HEADING-LINE1.
       DISPLAY DESIGN.
       DISPLAY HEADING-LINE2.

   INIT.
       INITIALIZE WS-TABLE.
       SET B-IDX TO 1.
       SET S-IDX TO 1.

       PERFORM READ-PAR
       PERFORM  LOAD  .

       PERFORM UNTIL EOF-SIRM
           MOVE SIRM-BANK-CODE TO WS-BANK-CODES(B-IDX)
           SET B-IDX UP BY 1
           MOVE SIR-STATUS-CODE  TO WS-STATUS-CODES(S-IDX)
           SET S-IDX UP BY 1
           MOVE 'N' TO EOF-SIRD-SW
           PERFORM UNTIL EOF-SIRD
               PERFORM READ-DETAIL
               IF SIRM-BANK-CODE = SIRD-BANK-CODE AND
                   SIRM-CK-ACH-NBR = SIRD-CHECK-NBR
               THEN
                   ADD 1 TO COUNTER
               ELSE
                   MOVE SIRM-BANK-CODE  TO DET-BANK-CODE
                   MOVE SIRM-CK-ACH-NBR TO DET-CHK-NBR
                   MOVE SIR-STATUS-CODE TO DET-STATUS-CODE
                   MOVE COUNTER TO DET-DETAIL-COUNT
                   DISPLAY DETAIL-LINE
                   MOVE 0 TO COUNTER
                   MOVE 'Y' TO EOF-SIRD-SW
               END-IF
           END-PERFORM
           PERFORM READ-PAR
       END-PERFORM.

   TERMINATION.
       CLOSE SIR-MASTER-FILE.
       CLOSE SIR-DETAIL-FILE.

   READ-PAR.
       READ SIR-MASTER-FILE  NEXT RECORD
       AT END
           MOVE 'Y' TO EOF-SIRM-SW
           DISPLAY '*******************************************'
       NOT AT END
           IF SIRM-FILE-STATUS IS NOT EQUAL TO '00'
           THEN
               GO TO ERROR-EXIT
           END-IF
       END-READ.

   READ-DETAIL.
       READ SIR-DETAIL-FILE NEXT RECORD
       AT END
           MOVE  'Y' TO EOF-SIRD-SW
       NOT AT END
           IF SIRD-FILE-STATUS IS NOT EQUAL TO '00'
           THEN
               GO TO ERROR-EXIT
           END-IF
       END-READ.

   ERROR-EXIT.
       DISPLAY 'INSIDE ERROR '
       DISPLAY '*************************************************'.
       DISPLAY '*    PROGRAM1 IS ABENDING   ABNORMALLY          *'.
       DISPLAY '*************************************************'.
       COMPUTE ABEND-RESULT = 1 / ZERO-VAR.
   END-ERROR.
 the values in the detail record is wrong in the below result
                CHECK MASTER VS DETAIL COUNT REPORT
                ************************************
 BANK CODE CHECK STATUS  STATUS CODE  DETAIL NO OF RECORDS 
 BC        2100000074     000          00079
 BC        2100000074     902          00000
 BC        2100000074     902          00000
 BC        2100000074     902          00000
 BC        2100000075     000          00014
 BC        2100000075     903          00000
 BC        2100000076     000          00049
 BC        2100000076     902          00000
 BC        2100000076     902          00000
 BC        2100000077     000          00014
 BC        2100000077     902          00000
 BC        2100000078     000          00051
 BC        2100000078     902          00000
 BC        2100000078     902          00000
 BC        2100000078     902          00000
 BC        2100000079     000          00610
 BC        2100000079     902          00000
 BC        2100000079     902          00000
 BC        2100000079     902          00000
 BC        2100000079     902          00000
 BC        2100000079     902          00000
 BC        2100000079     902          00000
 BC        2100000079     902          00000
 BC        2100000079     902          00000
 BC        2100000079     902          00000

0 个答案:

没有答案