我需要根据地区代码查找每个地区的政策数量。因此,每当我在记录中找到领土时,我需要增加表格中该区域的计数 然后我就可以将它移动到我的输出。我无法弄清楚如何根据以下记录计算每个地区的政策。我尝试过各种各样的东西但似乎没什么用。
如果您需要更多信息,请告诉我们。
以下是记录的定义和摘录(共57条记录)
rec-94-type pic x(2) rec-94-policy-number pic x(8) filler pic x(5) rec-94-parish-code pic x(3) filler pic x(1) rec-94-territory-code pic x(1) 94A 018517 080 1 94A 027721 090 1 94A 036470 250 6 94A 049137 010 1 ......
我最近的尝试:
05 T2-TERRITORY-COUNT.
10 FILLER PIC X(4) VALUE '1 '.
10 FILLER PIC X(4) VALUE '2 '.
10 FILLER PIC X(4) VALUE '3 '.
10 FILLER PIC X(4) VALUE '4 '.
10 FILLER PIC X(4) VALUE '5 '.
10 FILLER PIC X(4) VALUE '6 '.
10 FILLER PIC X(4) VALUE '7 '.
10 FILLER PIC X(4) VALUE '8 '.
10 FILLER PIC X(4) VALUE '9 '.
05 T2-TERRITORY-TABLE REDEFINES T2-TERRITORY-COUNT.
10 T2-ENTRY OCCURS 9 TIMES
INDEXED BY T2-INDEX.
15 T2-TERRITORY-CODE PIC X.
15 T2-TERRITORY-COUNTER PIC 999.
A000-MAINLINE.
PERFORM B000-OPENING-PROCEDURE.
PERFORM B600-PRINT-HEADINGS.
PERFORM B200-READ-FILE.
PERFORM B300-MAIN-PROCEDURE
UNTIL END-OF-FILE-SW = 'YES'.
PERFORM B800-MOVE-TERRITORY-CODE
VARYING T2-INDEX FROM 1 BY 1
UNTIL T2-INDEX > 9.
PERFORM B110-MOVE-COUNTS
PERFORM B100-CLOSING-PROCEDURE.
STOP RUN.
B000-OPENING-PROCEDURE.
OPEN OUTPUT REPORT-FILE.
OPEN OUTPUT PRINT-FILE.
OPEN INPUT INPUT-FILE.
B100-CLOSING-PROCEDURE.
PERFORM B500-PRINT-TOTAL-LINE.
CLOSE REPORT-FILE.
CLOSE PRINT-FILE.
CLOSE INPUT-FILE.
B200-READ-FILE.
READ INPUT-FILE INTO RECORD-TYPE-94
AT END MOVE 'YES' TO END-OF-FILE-SW.
B300-MAIN-PROCEDURE.
IF REC-94-TYPE = "94"
PERFORM B400-SEARCH-TERRITORY
PERFORM B900-COUNT-POLICIES
ELSE
WRITE REPORT-RECORD FROM RECORD-TYPE-94
END-IF.
ADD 1 TO A-LINE-COUNT.
PERFORM B200-READ-FILE.
B400-SEARCH-TERRITORY.
SET T1-INDEX TO 1.
SEARCH T1-ENTRY
AT END
DISPLAY 'PARISH NOT FOUND IN TABLE'
CALL 'CEE3ABD' USING BY VALUE 12 BY VALUE 1
WHEN
REC-94-PARISH-CODE = T1-PARISH(T1-INDEX)
MOVE T1-TERRITORY(T1-INDEX) TO
REC-94-TERRITORY-CODE
ADD 1 TO A-DISK-COUNTER
PERFORM B700-MOVE-RECORDS
END-SEARCH.
B500-PRINT-TOTAL-LINE.
MOVE A-LINE-COUNT TO TOTAL-RECORDS.
MOVE A-DISK-COUNTER TO TOTAL-POLICIES.
WRITE PRINT-RECORD FROM TOTAL-LINE.
B600-PRINT-HEADINGS.
ADD 1 TO A-PAGE-COUNT.
MOVE A-PAGE-COUNT TO PRINT-PAGE-NUMBER.
WRITE PRINT-RECORD FROM HEADER.
WRITE PRINT-RECORD FROM HEADER-LINE-2.
WRITE PRINT-RECORD FROM COLUMN-LINE.
B700-MOVE-RECORDS.
MOVE REC-94-TYPE TO REC-94-TYPE-OUT
MOVE REC-94-POLICY-NUMBER TO REC-94-POLICY-NUMBER-OUT
MOVE REC-94-PARISH-CODE TO REC-94-PARISH-CODE-OUT
MOVE REC-94-TERRITORY-CODE TO REC-94-TERRITORY-CODE-OUT
WRITE REPORT-RECORD FROM TRNREC94-OUT.
B800-MOVE-TERRITORY-CODE.
MOVE T2-TERRITORY-CODE(T2-INDEX) TO DET-TERRITORY.
WRITE PRINT-RECORD FROM DETAIL-LINE.
B900-COUNT-POLICIES.
MOVE ZEROES TO T2-TERRITORY-COUNTER(T2-INDEX).
SET T2-INDEX TO 1.
SEARCH T2-ENTRY
AT END
DISPLAY 'NO POLICIES FOUND.'
WHEN
REC-94-TERRITORY-CODE =
T2-TERRITORY-CODE(T2-INDEX)
ADD 1 TO T2-TERRITORY-COUNTER(T2-INDEX)
END-SEARCH.
MOVE T2-TERRITORY-COUNTER(T2-INDEX) TO DET-NUMBER-POLICIES.
WRITE PRINT-RECORD FROM DETAIL-LINE.
我会感激任何指示或只是正确的方向为此...提前感谢!
我的最终代码:
PERFORM B000-OPENING-PROCEDURE.
PERFORM B600-PRINT-HEADINGS.
PERFORM B200-READ-FILE.
PERFORM B300-MAIN-PROCEDURE
UNTIL END-OF-FILE-SW = 'YES'.
PERFORM C100-MOVE-COUNTS
VARYING T2-INDEX FROM 1 BY 1
UNTIL T2-INDEX > 9.
PERFORM B100-CLOSING-PROCEDURE.
STOP RUN.
B000-OPENING-PROCEDURE.
OPEN OUTPUT REPORT-FILE.
OPEN OUTPUT PRINT-FILE.
OPEN INPUT INPUT-FILE.
B100-CLOSING-PROCEDURE.
PERFORM B500-PRINT-TOTAL-LINE.
CLOSE REPORT-FILE.
CLOSE PRINT-FILE.
CLOSE INPUT-FILE.
B200-READ-FILE.
READ INPUT-FILE INTO RECORD-TYPE-94
AT END MOVE 'YES' TO END-OF-FILE-SW.
B300-MAIN-PROCEDURE.
IF REC-94-TYPE = "94"
PERFORM B400-SEARCH-TERRITORY
ELSE
WRITE REPORT-RECORD FROM RECORD-TYPE-94
END-IF.
ADD 1 TO A-LINE-COUNT.
PERFORM B200-READ-FILE.
B400-SEARCH-TERRITORY.
SET T1-INDEX TO 1.
SEARCH T1-ENTRY
AT END
DISPLAY 'PARISH NOT FOUND IN TABLE'
CALL 'CEE3ABD' USING BY VALUE 12 BY VALUE 1
WHEN
REC-94-PARISH-CODE = T1-PARISH(T1-INDEX)
MOVE T1-TERRITORY(T1-INDEX) TO
REC-94-TERRITORY-CODE
ADD 1 TO A-DISK-COUNTER
PERFORM B700-MOVE-RECORDS
PERFORM B900-COUNT-POLICIES
END-SEARCH.
B500-PRINT-TOTAL-LINE.
MOVE A-LINE-COUNT TO TOTAL-RECORDS.
MOVE A-DISK-COUNTER TO TOTAL-POLICIES.
WRITE PRINT-RECORD FROM TOTAL-LINE.
B600-PRINT-HEADINGS.
ADD 1 TO A-PAGE-COUNT.
MOVE A-PAGE-COUNT TO PRINT-PAGE-NUMBER.
WRITE PRINT-RECORD FROM HEADER.
WRITE PRINT-RECORD FROM HEADER-LINE-2.
WRITE PRINT-RECORD FROM COLUMN-LINE.
B700-MOVE-RECORDS.
MOVE REC-94-TYPE TO REC-94-TYPE-OUT
MOVE REC-94-POLICY-NUMBER TO REC-94-POLICY-NUMBER-OUT
MOVE REC-94-PARISH-CODE TO REC-94-PARISH-CODE-OUT
MOVE REC-94-TERRITORY-CODE TO REC-94-TERRITORY-CODE-OUT
WRITE REPORT-RECORD FROM TRNREC94-OUT.
B900-COUNT-POLICIES.
SET T2-INDEX TO 1.
SEARCH T2-ENTRY
AT END
DISPLAY 'NO POLICIES FOUND.'
WHEN
REC-94-TERRITORY-CODE = T2-TERRITORY-CODE(T2-INDEX)
DD 1 TO T2-TERRITORY-COUNTER(T2-INDEX)
END-SEARCH.
C100-MOVE-COUNTS.
MOVE T2-TERRITORY-CODE(T2-INDEX) TO DET-TERRITORY.
MOVE T2-TERRITORY-COUNTER(T2-INDEX) TO DET-NUMBER-POLICIES.
WRITE PRINT-RECORD FROM DETAIL-LINE.
答案 0 :(得分:5)
带有搜索语句的B900版本应该可以使用,但是从A000调用B900,只调用一次。将PERFORM B900语句移至B300,您应该为每个读取的记录收集计数。
此外,T2-TERRITORY-COUNTER用空格初始化。请用零初始化它。根据您的编译器,它可能没有什么区别,但如果它从零开始,则更容易理解变量的意图。
*更新*
您更新的代码仍有T2-TERRITORY-COUNTER空格。
也许以下内容会有所帮助。它基于您的代码,但删除了一些部分以使相关部分更易于查看。下面的代码适用于GNU Cobol(以前的OpenCobol - 请参阅sourceforge.net)。
IDENTIFICATION DIVISION.
PROGRAM-ID. COUNT-TERRITORY.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT POLICY-FILE ASSIGN TO 'POLICY.DAT'
FILE STATUS IS POLICY-FILE-STATUS
ORGANIZATION IS LINE SEQUENTIAL.
SELECT REPORT-FILE ASSIGN TO 'POLICY.RPT'
FILE STATUS IS REPORT-FILE-STATUS
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD POLICY-FILE.
01 POLICY-RECORD PIC X(20).
FD REPORT-FILE.
01 REPORT-RECORD PIC X(132).
WORKING-STORAGE SECTION.
01 IS-POLICY-FILE-AT-END PIC XXX VALUE 'NO '.
88 POLICY-FILE-AT-END VALUE 'YES'.
01 POLICY-FILE-STATUS PIC 9(2).
88 POLICY-FILE-OK VALUES 0 10.
* VALUE 00 = SUCCESS
* VALUE 10 = END OF FILE
01 REPORT-FILE-STATUS PIC 9(2).
88 REPORT-FILE-OK VALUES 0 10.
* VALUE 00 = SUCCESS
* VALUE 10 = END OF FILE
01 RECORD-TYPE-94.
05 REC-94-TYPE PIC X(2).
88 INCLUDED-RECORD-TYPE VALUE '94'.
05 REC-94-POLICY-NUMBER PIC X(8).
05 FILLER PIC X(5).
05 REC-94-PARISH-CODE PIC X(3).
05 FILLER PIC X(1).
05 REC-94-TERRITORY-CODE PIC X(1).
01 T2-TERRITORY-COUNT.
05 FILLER PIC X(4) VALUE '1000'.
05 FILLER PIC X(4) VALUE '2000'.
05 FILLER PIC X(4) VALUE '3000'.
05 FILLER PIC X(4) VALUE '4000'.
05 FILLER PIC X(4) VALUE '5000'.
05 FILLER PIC X(4) VALUE '6000'.
05 FILLER PIC X(4) VALUE '7000'.
05 FILLER PIC X(4) VALUE '8000'.
05 FILLER PIC X(4) VALUE '9000'.
01 T2-TERRITORY-TABLE REDEFINES T2-TERRITORY-COUNT.
05 T2-ENTRY OCCURS 9 TIMES
INDEXED BY T2-INDEX.
10 T2-TERRITORY-CODE PIC X.
10 T2-TERRITORY-COUNTER PIC 999.
PROCEDURE DIVISION.
A000-MAINLINE.
PERFORM B000-OPENING-PROCEDURE
PERFORM B200-READ-FILE
PERFORM B300-MAIN-PROCEDURE
UNTIL POLICY-FILE-AT-END
PERFORM C100-WRITE-TERRITORY-COUNTS
PERFORM B100-CLOSING-PROCEDURE
STOP RUN
.
B000-OPENING-PROCEDURE.
OPEN INPUT POLICY-FILE
OPEN OUTPUT REPORT-FILE
.
B100-CLOSING-PROCEDURE.
CLOSE POLICY-FILE
CLOSE REPORT-FILE
.
B200-READ-FILE.
READ POLICY-FILE INTO RECORD-TYPE-94
AT END SET POLICY-FILE-AT-END TO TRUE
PERFORM D100-CHECK-POLICY-FILE-STATUS
.
B300-MAIN-PROCEDURE.
IF INCLUDED-RECORD-TYPE
PERFORM B900-COUNT-POLICIES
ELSE
WRITE REPORT-RECORD FROM RECORD-TYPE-94
PERFORM D200-CHECK-REPORT-FILE-STATUS
END-IF
PERFORM B200-READ-FILE
.
B900-COUNT-POLICIES.
SET T2-INDEX TO 1
SEARCH T2-ENTRY
AT END
DISPLAY 'TERRITORY ' REC-94-TERRITORY-CODE
' UNKNOWN'
WHEN REC-94-TERRITORY-CODE = T2-TERRITORY-CODE (T2-INDEX)
ADD 1 TO T2-TERRITORY-COUNTER (T2-INDEX)
END-SEARCH
.
C100-WRITE-TERRITORY-COUNTS.
MOVE SPACES TO REPORT-RECORD
WRITE REPORT-RECORD
PERFORM D200-CHECK-REPORT-FILE-STATUS
PERFORM VARYING T2-INDEX FROM 1 BY 1
UNTIL T2-INDEX > 9
STRING 'POLICY COUNT FOR TERRITORY '
T2-TERRITORY-CODE (T2-INDEX)
': '
T2-TERRITORY-COUNTER (T2-INDEX)
INTO REPORT-RECORD
WRITE REPORT-RECORD
PERFORM D200-CHECK-REPORT-FILE-STATUS
END-PERFORM
.
D100-CHECK-POLICY-FILE-STATUS.
IF NOT POLICY-FILE-OK
DISPLAY 'ERROR CODE READING POLICY FILE: '
POLICY-FILE-STATUS
END-IF
.
D200-CHECK-REPORT-FILE-STATUS.
IF NOT REPORT-FILE-OK
DISPLAY 'ERROR CODE WRITING REPORT FILE: '
POLICY-FILE-STATUS
END-IF
.
IDENTIFICATION DIVISION.
PROGRAM-ID. COUNT-TERRITORY.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT POLICY-FILE ASSIGN TO 'POLICY.DAT'
FILE STATUS IS POLICY-FILE-STATUS
ORGANIZATION IS LINE SEQUENTIAL.
SELECT REPORT-FILE ASSIGN TO 'POLICY.RPT'
FILE STATUS IS REPORT-FILE-STATUS
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD POLICY-FILE.
01 POLICY-RECORD PIC X(20).
FD REPORT-FILE.
01 REPORT-RECORD PIC X(132).
WORKING-STORAGE SECTION.
01 IS-POLICY-FILE-AT-END PIC XXX VALUE 'NO '.
88 POLICY-FILE-AT-END VALUE 'YES'.
01 POLICY-FILE-STATUS PIC 9(2).
88 POLICY-FILE-OK VALUES 0 10.
* VALUE 00 = SUCCESS
* VALUE 10 = END OF FILE
01 REPORT-FILE-STATUS PIC 9(2).
88 REPORT-FILE-OK VALUES 0 10.
* VALUE 00 = SUCCESS
* VALUE 10 = END OF FILE
01 RECORD-TYPE-94.
05 REC-94-TYPE PIC X(2).
88 INCLUDED-RECORD-TYPE VALUE '94'.
05 REC-94-POLICY-NUMBER PIC X(8).
05 FILLER PIC X(5).
05 REC-94-PARISH-CODE PIC X(3).
05 FILLER PIC X(1).
05 REC-94-TERRITORY-CODE PIC X(1).
01 T2-TERRITORY-COUNT.
05 FILLER PIC X(4) VALUE '1000'.
05 FILLER PIC X(4) VALUE '2000'.
05 FILLER PIC X(4) VALUE '3000'.
05 FILLER PIC X(4) VALUE '4000'.
05 FILLER PIC X(4) VALUE '5000'.
05 FILLER PIC X(4) VALUE '6000'.
05 FILLER PIC X(4) VALUE '7000'.
05 FILLER PIC X(4) VALUE '8000'.
05 FILLER PIC X(4) VALUE '9000'.
01 T2-TERRITORY-TABLE REDEFINES T2-TERRITORY-COUNT.
05 T2-ENTRY OCCURS 9 TIMES
INDEXED BY T2-INDEX.
10 T2-TERRITORY-CODE PIC X.
10 T2-TERRITORY-COUNTER PIC 999.
PROCEDURE DIVISION.
A000-MAINLINE.
PERFORM B000-OPENING-PROCEDURE
PERFORM B200-READ-FILE
PERFORM B300-MAIN-PROCEDURE
UNTIL POLICY-FILE-AT-END
PERFORM C100-WRITE-TERRITORY-COUNTS
PERFORM B100-CLOSING-PROCEDURE
STOP RUN
.
B000-OPENING-PROCEDURE.
OPEN INPUT POLICY-FILE
OPEN OUTPUT REPORT-FILE
.
B100-CLOSING-PROCEDURE.
CLOSE POLICY-FILE
CLOSE REPORT-FILE
.
B200-READ-FILE.
READ POLICY-FILE INTO RECORD-TYPE-94
AT END SET POLICY-FILE-AT-END TO TRUE
PERFORM D100-CHECK-POLICY-FILE-STATUS
.
B300-MAIN-PROCEDURE.
IF INCLUDED-RECORD-TYPE
PERFORM B900-COUNT-POLICIES
ELSE
WRITE REPORT-RECORD FROM RECORD-TYPE-94
PERFORM D200-CHECK-REPORT-FILE-STATUS
END-IF
PERFORM B200-READ-FILE
.
B900-COUNT-POLICIES.
SET T2-INDEX TO 1
SEARCH T2-ENTRY
AT END
DISPLAY 'TERRITORY ' REC-94-TERRITORY-CODE
' UNKNOWN'
WHEN REC-94-TERRITORY-CODE = T2-TERRITORY-CODE (T2-INDEX)
ADD 1 TO T2-TERRITORY-COUNTER (T2-INDEX)
END-SEARCH
.
C100-WRITE-TERRITORY-COUNTS.
MOVE SPACES TO REPORT-RECORD
WRITE REPORT-RECORD
PERFORM D200-CHECK-REPORT-FILE-STATUS
PERFORM VARYING T2-INDEX FROM 1 BY 1
UNTIL T2-INDEX > 9
STRING 'POLICY COUNT FOR TERRITORY '
T2-TERRITORY-CODE (T2-INDEX)
': '
T2-TERRITORY-COUNTER (T2-INDEX)
INTO REPORT-RECORD
WRITE REPORT-RECORD
PERFORM D200-CHECK-REPORT-FILE-STATUS
END-PERFORM
.
D100-CHECK-POLICY-FILE-STATUS.
IF NOT POLICY-FILE-OK
DISPLAY 'ERROR CODE READING POLICY FILE: '
POLICY-FILE-STATUS
END-IF
.
D200-CHECK-REPORT-FILE-STATUS.
IF NOT REPORT-FILE-OK
DISPLAY 'ERROR CODE WRITING REPORT FILE: '
POLICY-FILE-STATUS
END-IF
.
答案 1 :(得分:1)
在达到文件结尾后,您只执行一次B900-COUNT-POLICIES。
B900-也只是使用T2-INDEX最后的价值。
你有两个主要的选择:要么做一个循环;或者,假设您的区域为零到小于或等于九 - 在这种情况下,您可以使用区域的值来设置索引的值并添加。 SEARCH是可能的(它不适合你的原因仍然只是在文件结束后执行段落,而不是每条记录),但根据我的经验,它不是为这种类型选择的方法任务。
如果要使用区域来获取要用于ADD的索引的值,请使用SET:
SET T2-INDEX TO rec-94-territory-code
除了你不能。 rec-94-territory-code是一个字母数字(PIC X字段。这适用于计算中未使用的任何内容)。在WORKING-STORAGE和第一个
中定义一个新的数字字段是没有问题的MOVE rec-94-territory-code TO new-numeric-field
然后
SET T2-INDEX TO new-numeric-field
对于循环,我认为你已经可以到达那里了。
但是,在您进行任何一种方式添加之前,如果您的每个区域的计数从零开始,那将是一个好主意。你的太空了。即使这“有效”,也不是好事。
所以你需要从零开始 - 一个循环现在很好。
根据您的代码更改,您的下一个问题是您是如何尝试将初始值设置为计数表的。
现在,在OPEN段落之后添加一个段落并执行新段落。在该段落中,创建一个循环,将表中的值设置为零,从第一个开始到第九个结束。