索引文件错误

Indexed File Error

我正在尝试按索引打开文件,但不断收到以下错误。从我能找到的所有 COBOL 代码示例中,我看不出我的错误在哪里。

我可以按顺序打开文件。尝试按索引打开它似乎有点问题。

错误:

project2.cbl:119: libcob: Permanent file error (STATUS = 30) File : 'customers.dat'

系统:

OS X

GnuCOBOL

OpenCobolIDE
Version: 4.7.3

代码:

   IDENTIFICATION DIVISION.
   PROGRAM-ID. PROJECT-2.

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

       SELECT CUST-FILE ASSIGN TO "customers.dat"
           ORGANIZATION IS INDEXED
           ACCESS IS RANDOM
           RECORD KEY IS CUST-ID.

       SELECT INV-FILE ASSIGN TO "inventory.dat"
           ORGANIZATION IS INDEXED
           ACCESS IS RANDOM
           RECORD KEY IS ITEM-ID.

       SELECT TRANS-FILE ASSIGN TO "transactions.dat"
           ORGANIZATION IS LINE SEQUENTIAL.

       SELECT SORTED-TRANS-FILE ASSIGN TO "sorted-transactions.dat"
           ORGANIZATION IS LINE SEQUENTIAL.

       SELECT WORK-TRANS-FILE ASSIGN TO "work-transaction.dat".

   DATA DIVISION.
   FILE SECTION.

   FD  CUST-FILE.
   01  CUST-RECORD.
       05  CUST-ID         PIC 9(10).
       05  NAME            PIC A(23).
       05  STREET          PIC X(23).
       05  CITY            PIC A(13).
       05  STATE           PIC A(12).
       05  AMT-DUE         PIC 9(3).99.

   FD  INV-FILE.
   01  INV-RECORD.
       05  ITEM-ID         PIC 9(11).
       05  DESC            PIC A(24).
       05  OH              PIC 9(7).
       05  MIN-STK         PIC 9(7).
       05  PRICE           PIC 9(2).99.

   FD  TRANS-FILE.
   01  TRANS-RECORD.
       05  CUST            PIC 9(10).
       05  ITEM            PIC 9(12).
       05  QTY             PIC 9(6).
       05  SALE-CD         PIC X(1).
           88  10-OFF      VALUE "A".
           88  20-OFF      VALUE "B".
           88  25-OFF      VALUE "C".
           88  3-GET-1     VALUE "D".
           88  1-GET-1     VALUE "E".
           88  NO-DISC     VALUE "Z".

   FD  SORTED-TRANS-FILE.
   01  SORTED-TRANS-RECORD.
       05  S-CUST          PIC 9(10).
       05  S-ITEM          PIC 9(12).
       05  S-QTY           PIC 9(6).
       05  S-SALE-CD       PIC X(1).
           88  10-OFF      VALUE "A".
           88  20-OFF      VALUE "B".
           88  25-OFF      VALUE "C".
           88  3-GET-1     VALUE "D".
           88  1-GET-1     VALUE "E".
           88  NO-DISC     VALUE "Z".

   SD  WORK-TRANS-FILE.
   01  WORK-TRANS-RECORD.
       05  W-CUST          PIC 9(10).
       05  W-ITEM          PIC 9(12).
       05  W-QTY           PIC 9(6).
       05  W-SALE-CD       PIC X(1).
           88  10-OFF      VALUE "A".
           88  20-OFF      VALUE "B".
           88  25-OFF      VALUE "C".
           88  3-GET-1     VALUE "D".
           88  1-GET-1     VALUE "E".
           88  NO-DISC     VALUE "Z".

   WORKING-STORAGE SECTION.
   01  SWITCHES.
       05 C-EOF-SWITCH     PIC X VALUE "N".
       05 I-EOF-SWITCH     PIC X VALUE "N".
       05 T-EOF-SWITCH     PIC X VALUE "N".
       05 S-EOF-SWITCH     PIC X VALUE "N".

   01  COUNTERS.
       05 REC-COUNTER-C    PIC 9(3) VALUE 0.
       05 REC-COUNTER-I    PIC 9(3) VALUE 0.
       05 REC-COUNTER-T    PIC 9(3) VALUE 0.
       05 REC-COUNTER-S    PIC 9(3) VALUE 0.

   PROCEDURE DIVISION.
   MAIN-PROCEDURE.

       PERFORM 100-INITIALIZE.
       PERFORM 200-SORT-TRANSACTIONS.
       PERFORM 300-CUSTOMER-INVOICE
           UNTIL S-EOF-SWITCH = "Y".
       PERFORM 900-TERMINATE.

       STOP RUN.

   100-INITIALIZE.
       OPEN I-O CUST-FILE.
       READ CUST-FILE
           AT END
               MOVE "Y" TO C-EOF-SWITCH
           NOT AT END
               COMPUTE REC-COUNTER-C = REC-COUNTER-C + 1
       END-READ.

       OPEN I-O INV-FILE.
       READ INV-FILE
           AT END
               MOVE "Y" TO I-EOF-SWITCH
           NOT AT END
               COMPUTE REC-COUNTER-I = REC-COUNTER-I + 1
       END-READ.

       OPEN INPUT TRANS-FILE.
       READ TRANS-FILE
           AT END
               MOVE "Y" TO T-EOF-SWITCH
           NOT AT END
               COMPUTE REC-COUNTER-T = REC-COUNTER-T + 1
       END-READ.

   200-SORT-TRANSACTIONS.
       SORT WORK-TRANS-FILE ON ASCENDING W-CUST
       USING  TRANS-FILE
       GIVING SORTED-TRANS-FILE.

   300-CUSTOMER-INVOICE.

       DISPLAY S-CUST.
       DISPLAY S-ITEM.
       DISPLAY S-QTY.
       DISPLAY S-SALE-CD.
       DISPLAY " ".

       READ SORTED-TRANS-FILE
           AT END
               MOVE "Y" TO S-EOF-SWITCH
           NOT AT END
               COMPUTE REC-COUNTER-S = REC-COUNTER-S + 1
       END-READ.

   900-TERMINATE.
       DISPLAY "Number of Customers: " REC-COUNTER-C.
       DISPLAY "Number of Transactions: " REC-COUNTER-T.
       DISPLAY "Number of Inventory Items: " REC-COUNTER-I.
       CLOSE CUST-FILE.
       CLOSE INV-FILE.
       CLOSE TRANS-FILE.

   END PROGRAM PROJECT-2.

文件内容:

01001     Steve Howe             123 Topographic Rd     London       England     000.00
01002     Geddy Lee              4385 Xanadu Ln         Toronto      Canada      058.15
01003     Steve Hackett          16 Serpentine Dr       London       England     134.10
01005     Nancy Wilson           5763 Butterfly St      Seattle      Washington  018.95
01008     Andy Latimer           858 Sasquatch St       Leeds        England     857.44
01015     Dweezil Zappa          86 Yerbouti Blvd       Los Angeles  California  000.00
01019     Roine Stolt            2332 Retropolis        Stockholm    Sweden      069.95
01023     Tal Wilkenfeld         52525 Beck Way         Sydney       Australia   200.00
01044     Todd Rundgren          662 Utopia St          Los Angeles  California  157.21
01088     Mike Rutherford        91 N Broadway          New York     New York    000.00

顺序文件不能作为索引文件打开。这是一种完全不同的文件类型。

您可能想要 OPEN OUTPUT CUST-FILE,从顺序文件和 WRITE CUST-FILE FROM seq-record 中读取您的客户。之后您的 OPEN INPUT CUST-FILE 将起作用(取决于您想要实现的目标,将数据读入临时和有序的 table 可能更好,然后使用 SEARCH ALL 获取特定记录。