奇怪的 COBOL 错误

发布于 2024-09-11 07:47:51 字数 11798 浏览 5 评论 0原文

首先,这是完整的源代码: http://pastebin.com/5teGNrPC

*>
 IDENTIFICATION DIVISION.
 PROGRAM-ID.   CAddress.
 ENVIRONMENT    DIVISION.
 CONFIGURATION  SECTION.
 INPUT-OUTPUT SECTION.
 FILE-CONTROL.
           SELECT TelephoneBookFile
                   ASSIGN TO "phonebook.db"
                   ORGANIZATION IS INDEXED
                   RECORD KEY IS user-record-key
                   ACCESS MODE IS DYNAMIC.
 DATA DIVISION.
 FILE SECTION.
        FD TelephoneBookFile
                LABEL RECORDS ARE STANDARD.
        01 User-Record-File.
                05  user-record-key        PIC X(35).
                05  user-record-first-name PIC X(24).
        05  user-record-last-name  PIC X(50).
        05  user-record-address    PIC X(50).
        05  user-record-city       PIC X(16).
        05  user-record-zip        PIC X(8) .
        05  user-record-country    PIC X(20).
        05  user-record-telephone  PIC X(16).


 WORKING-STORAGE SECTION.
  77  menu-hoofd-invoer  PICTURE 9(1) VALUE 9.
        88  menu-invoer-correct  VALUE 0 THRU 5.
        88  menu-invoer-incorrect VALUE 6 THRU 9.
        88  menu-invoer-afsluiten VALUE 0.
        88  menu-invoer-record-toevoegen VALUE 1.
        88  menu-invoer-nieuw-bestand VALUE 5.
  77  Error-Msg  PICTURE X(30) VALUE "                              ".
  77  Green-Msg  PICTURE X(30) VALUE "                              ".
  77  file-status PICTURE X(3) VALUE " ".
        88  file-status-eof VALUE "EOF".
  01  User-Record.
        05  user-first-name PIC X(24).
        05  user-last-name  PIC X(50).
        05  user-address    PIC X(50).
        05  user-city       PIC X(16).
        05  user-zip        PIC X(8) .
        05  user-country    PIC X(20).
        05  user-telephone  PIC X(16).
  77  Yes-No-Correct-Field PICTURE X(1) VALUE " ".
        88  yes-no-field-yes   VALUE "Y" "y".
        88  yes-no-field-no    VALUE "N" "n".
        88  yes-no-field-correct VALUE "C" "c".
  77  Record-Count   PIC 9(5) VALUE 0.
  77  Error-Screen-Msg PIC X(45) VALUE SPACES.
  77  Navigate-Field PICTURE X(1) VALUE " ".
        88 Navigate-Next           VALUE "N" "n".
        88 Navigate-Prev           VALUE "P" "p".
        88 Navigate-Exit           VALUE "X" "x".
  77  Error-Continue-Flag PIC X(1) VALUE " ".
        88 Error-Continue-OK   VALUE "C" "c".
 SCREEN SECTION.
        01      MainMenu.
                05 BLANK SCREEN.
                05 LINE 1  COLUMN 1  VALUE " CAddress - A COBOL Address Book".
                05 LINE 2  COLUMN 1  VALUE " -------------------------------".
                05 LINE 4  COLUMN 1  VALUE "   Make your choice: ".
                05 LINE 5  COLUMN 1  VALUE "   ~~~~~~~~~~~~~~~~~ ".
                05 LINE 7  COLUMN 1  VALUE "       1) Add record".
                05 LINE 8  COLUMN 1  VALUE "       2) Delete record".
                05 LINE 9  COLUMN 1  VALUE "       3) Look up record".
                05 LINE 10 COLUMN 1  VALUE "       4) Show records".
                05 LINE 11 COLUMN 1  VALUE "       5) Create new file".
                05 LINE 13 COLUMN 1  VALUE "       0) Exit".
                05 LINE 15 COLUMN 1  VALUE "             Choice? ".
                05 LINE 15 COLUMN 25 PICTURE X(30) FROM Error-Msg FOREGROUND-COLOR 4.
                05 LINE 24 COLUMN 1  VALUE " (c) YvanSoftware ".
        01  InvoerMenu.
                05 BLANK SCREEN.
                05 LINE 1  COLUMN 1  VALUE " CAddress - A COBOL Address Book".
                05 LINE 2  COLUMN 1  VALUE " -------------------------------".
                05 LINE 4  COLUMN 1  VALUE "   Input Data".
                05 LINE 5  COLUMN 1  VALUE "   ~~~~~~~~~~".
                05 LINE 7  COLUMN 1  VALUE "   First name   :" FOREGROUND-COLOR 2.
                05 LINE 8  COLUMN 1  VALUE "   Last name    :" FOREGROUND-COLOR 2.
                05 LINE 9  COLUMN 1  VALUE "   Address      :" FOREGROUND-COLOR 2.
                05 LINE 10 COLUMN 1  VALUE "   City         :" FOREGROUND-COLOR 2.
                05 LINE 11 COLUMN 1  VALUE "   ZIP          :" FOREGROUND-COLOR 2.
                05 LINE 12 COLUMN 1  VALUE "   Country      :" FOREGROUND-COLOR 2.
                05 LINE 13 COLUMN 1  VALUE "   Telephone    :" FOREGROUND-COLOR 2.
                05 LINE 15 COLUMN 1  VALUE "       Save? y(es)/n(o)/c(orrect) " FOREGROUND-COLOR 4.
                05 LINE 24 COLUMN 1  VALUE " (c) YvanSoftware ".
        01  UitvoerScherm.
                05 BLANK SCREEN.
                05 LINE 1  COLUMN 1  VALUE " CAddress - A COBOL Address Book".
                05 LINE 2  COLUMN 1  VALUE " -------------------------------".
                05 LINE 4  COLUMN 1  VALUE "   Find Data".
                05 LINE 5  COLUMN 1  VALUE "   ~~~~~~~~~~".
                05 LINE 7  COLUMN 1  VALUE "   First name   :" FOREGROUND-COLOR 2.
                05 LINE 8  COLUMN 1  VALUE "   Last name    :" FOREGROUND-COLOR 2.
                05 LINE 9  COLUMN 1  VALUE "   Address      :" FOREGROUND-COLOR 2.
                05 LINE 10 COLUMN 1  VALUE "   City         :" FOREGROUND-COLOR 2.
                05 LINE 11 COLUMN 1  VALUE "   ZIP          :" FOREGROUND-COLOR 2.
                05 LINE 12 COLUMN 1  VALUE "   Country      :" FOREGROUND-COLOR 2.
                05 LINE 13 COLUMN 1  VALUE "   Telephone    :" FOREGROUND-COLOR 2.
* Col 45 Input
                05 LINE 15 COLUMN 1  VALUE "         Navigate? n(ext)/p(revious)/x(exit) " FOREGROUND-COLOR 4.
                05 LINE 24 COLUMN 1  VALUE " (c) YvanSoftware ".
        01  FoutScherm.
                05 BLANK SCREEN.
                05 LINE 4  COLUMN 15 VALUE "====================(ERROR)======================" BACKGROUND-COLOR 4 FOREGROUND-COLOR 7.
                05 LINE 5  COLUMN 15 VALUE "                                                 " BACKGROUND-COLOR 4 FOREGROUND-COLOR 7.
                05 LINE 6  COLUMN 15 VALUE "                                                 " BACKGROUND-COLOR 4 FOREGROUND-COLOR 7.
                05 LINE 7  COLUMN 15 VALUE "                                                 " BACKGROUND-COLOR 4 FOREGROUND-COLOR 7.
                05 LINE 8  COLUMN 15 VALUE "                                                 " BACKGROUND-COLOR 4 FOREGROUND-COLOR 7.
                05 LINE 10 COLUMN 15 VALUE "                INPUT C TO CONTINUE              " BACKGROUND-COLOR 4 FOREGROUND-COLOR 7.
                05 LINE 6  COLUMN 18 PICTURE X(45) FROM Error-screen-msg BACKGROUND-COLOR 4 FOREGROUND-COLOR 7 BLINK.
 PROCEDURE DIVISION.      
  main.
        PERFORM Show-MainMenu UNTIL menu-invoer-afsluiten.
        STOP RUN.
     .
  Show-MainMenu.
        DISPLAY MainMenu
        ACCEPT menu-hoofd-invoer LINE 15 COLUMN 22.
        IF menu-invoer-incorrect
        THEN
                MOVE " Incorrect input" TO Error-Msg
                MOVE " " TO Green-Msg
        END-IF.
        IF menu-invoer-record-toevoegen
        THEN
                PERFORM Show-InvoerMenu
        END-IF
        IF menu-invoer-nieuw-bestand
        THEN
                PERFORM Show-NewFile
        END-IF.
     .
  Show-InvoerMenu.
        DISPLAY InvoerMenu.
        ACCEPT user-first-name      LINE 7  COLUMN 18
                WITH FOREGROUND-COLOR 4.
        ACCEPT user-last-name       LINE 8  COLUMN 18
                WITH FOREGROUND-COLOR 4.
        ACCEPT user-address         LINE 9  COLUMN 18
                WITH FOREGROUND-COLOR 4.
        ACCEPT user-city            LINE 10 COLUMN 18
                WITH FOREGROUND-COLOR 4.
        ACCEPT user-zip             LINE 11 COLUMN 18
                WITH FOREGROUND-COLOR 4.
        ACCEPT user-country         LINE 12 COLUMN 18
                WITH FOREGROUND-COLOR 4.
        ACCEPT user-telephone       LINE 13 COLUMN 18
                WITH FOREGROUND-COLOR 4.

        PERFORM AskForSave.
  .
  Show-NewFile.
        DISPLAY InvoerMenu.
        ACCEPT user-first-name      LINE 7  COLUMN 18
                WITH FOREGROUND-COLOR 4.
        ACCEPT user-last-name       LINE 8  COLUMN 18
                WITH FOREGROUND-COLOR 4.
        ACCEPT user-address         LINE 9  COLUMN 18
                WITH FOREGROUND-COLOR 4.
        ACCEPT user-city            LINE 10 COLUMN 18
                WITH FOREGROUND-COLOR 4.
        ACCEPT user-zip             LINE 11 COLUMN 18
                WITH FOREGROUND-COLOR 4.
        ACCEPT user-country         LINE 12 COLUMN 18
                WITH FOREGROUND-COLOR 4.
        ACCEPT user-telephone       LINE 13 COLUMN 18
                WITH FOREGROUND-COLOR 4.

        PERFORM AskForSaveNew.

  AskForSave.  
        ACCEPT Yes-No-Correct-Field LINE 15 COLUMN 35
                WITH FOREGROUND-COLOR 2.

        IF Yes-No-Field-Correct
        THEN
                PERFORM Show-InvoerMenu
        END-IF.

        IF Yes-No-Field-No
        THEN
                PERFORM Show-MainMenu
        END-IF.

        IF Yes-No-Field-Yes
        THEN
                PERFORM Save-Record
        END-IF.

        IF NOT Yes-No-Field-No AND NOT Yes-No-Field-Yes AND NOT Yes-No-Field-Correct
        THEN
                PERFORM AskForSave
        END-IF.
        .
  Save-Record.
        OPEN I-O TelephoneBookFile.
        PERFORM AddRecordKey.
        MOVE user-first-name TO user-record-first-name.
        MOVE user-last-name  TO user-record-last-name .
        MOVE user-address    TO user-record-address   .
        MOVE user-city       TO user-record-city      .
        MOVE user-zip        TO user-record-zip       .
        MOVE user-country    TO user-record-country   .
        MOVE user-telephone  TO user-record-telephone .
        WRITE User-Record-File INVALID KEY PERFORM ExistsAlready.
        CLOSE TelephoneBookFile
        .
  AskForSaveNew.       
        ACCEPT Yes-No-Correct-Field LINE 15 COLUMN 35
                WITH FOREGROUND-COLOR 2.

        IF Yes-No-Field-Correct
        THEN
                PERFORM Show-NewFile
        END-IF.

        IF Yes-No-Field-No
        THEN
                PERFORM Show-MainMenu
        END-IF.

        IF Yes-No-Field-Yes
        THEN
                PERFORM Save-Record-NewFile
        END-IF.

        IF NOT Yes-No-Field-No AND NOT Yes-No-Field-Yes AND NOT Yes-No-Field-Correct
        THEN
                PERFORM AskForSave
        END-IF.
        .
  Save-Record-NewFile.
                OPEN OUTPUT TelephoneBookFile.
                PERFORM AddRecordKey.

        MOVE user-first-name TO user-record-first-name.
        MOVE user-last-name  TO user-record-last-name .
        MOVE user-address    TO user-record-address   .
        MOVE user-city       TO user-record-city      .
        MOVE user-zip        TO user-record-zip       .
        MOVE user-country    TO user-record-country   .
        MOVE user-telephone  TO user-record-telephone .
        WRITE User-Record-File.
        CLOSE TelephoneBookFile.
        .
  AddRecordKey.
        STRING user-first-name(1:5) user-last-name(1:5)
                   user-address(1:5) user-city(1:5)
                   user-zip(1:5) user-country(1:5)
                   user-telephone(1:5)
                DELIMITED BY SIZE
                INTO user-record-key
        .
  ExistsAlready.
        MOVE "Record already exists" TO Error-Screen-Msg
        PERFORM ErrorScreen
      .
  ErrorScreen.
        DISPLAY FoutScherm
        ACCEPT  Error-Continue-Flag LINE 24 COLUMN 80
        IF NOT Error-Continue-OK
        THEN
                Perform ErrorScreen
        END-IF.
        .  
 END PROGRAM CAddress.

我收到一个奇怪的 COBOL 错误,但我找不到这意味着什么。 它显示“打开错误”(请参阅​​以下屏幕截图)。

如果我首先使用“新文件”,然后添加一条记录,则不会发生这种情况。

这里应用程序二进制文件及其生成的一些日志文件。

非常感谢,

Yvan

PS:这是 Fujitsu NetCobol 方言。

First of all, here's the full source code:
http://pastebin.com/5teGNrPC

*>
 IDENTIFICATION DIVISION.
 PROGRAM-ID.   CAddress.
 ENVIRONMENT    DIVISION.
 CONFIGURATION  SECTION.
 INPUT-OUTPUT SECTION.
 FILE-CONTROL.
           SELECT TelephoneBookFile
                   ASSIGN TO "phonebook.db"
                   ORGANIZATION IS INDEXED
                   RECORD KEY IS user-record-key
                   ACCESS MODE IS DYNAMIC.
 DATA DIVISION.
 FILE SECTION.
        FD TelephoneBookFile
                LABEL RECORDS ARE STANDARD.
        01 User-Record-File.
                05  user-record-key        PIC X(35).
                05  user-record-first-name PIC X(24).
        05  user-record-last-name  PIC X(50).
        05  user-record-address    PIC X(50).
        05  user-record-city       PIC X(16).
        05  user-record-zip        PIC X(8) .
        05  user-record-country    PIC X(20).
        05  user-record-telephone  PIC X(16).


 WORKING-STORAGE SECTION.
  77  menu-hoofd-invoer  PICTURE 9(1) VALUE 9.
        88  menu-invoer-correct  VALUE 0 THRU 5.
        88  menu-invoer-incorrect VALUE 6 THRU 9.
        88  menu-invoer-afsluiten VALUE 0.
        88  menu-invoer-record-toevoegen VALUE 1.
        88  menu-invoer-nieuw-bestand VALUE 5.
  77  Error-Msg  PICTURE X(30) VALUE "                              ".
  77  Green-Msg  PICTURE X(30) VALUE "                              ".
  77  file-status PICTURE X(3) VALUE " ".
        88  file-status-eof VALUE "EOF".
  01  User-Record.
        05  user-first-name PIC X(24).
        05  user-last-name  PIC X(50).
        05  user-address    PIC X(50).
        05  user-city       PIC X(16).
        05  user-zip        PIC X(8) .
        05  user-country    PIC X(20).
        05  user-telephone  PIC X(16).
  77  Yes-No-Correct-Field PICTURE X(1) VALUE " ".
        88  yes-no-field-yes   VALUE "Y" "y".
        88  yes-no-field-no    VALUE "N" "n".
        88  yes-no-field-correct VALUE "C" "c".
  77  Record-Count   PIC 9(5) VALUE 0.
  77  Error-Screen-Msg PIC X(45) VALUE SPACES.
  77  Navigate-Field PICTURE X(1) VALUE " ".
        88 Navigate-Next           VALUE "N" "n".
        88 Navigate-Prev           VALUE "P" "p".
        88 Navigate-Exit           VALUE "X" "x".
  77  Error-Continue-Flag PIC X(1) VALUE " ".
        88 Error-Continue-OK   VALUE "C" "c".
 SCREEN SECTION.
        01      MainMenu.
                05 BLANK SCREEN.
                05 LINE 1  COLUMN 1  VALUE " CAddress - A COBOL Address Book".
                05 LINE 2  COLUMN 1  VALUE " -------------------------------".
                05 LINE 4  COLUMN 1  VALUE "   Make your choice: ".
                05 LINE 5  COLUMN 1  VALUE "   ~~~~~~~~~~~~~~~~~ ".
                05 LINE 7  COLUMN 1  VALUE "       1) Add record".
                05 LINE 8  COLUMN 1  VALUE "       2) Delete record".
                05 LINE 9  COLUMN 1  VALUE "       3) Look up record".
                05 LINE 10 COLUMN 1  VALUE "       4) Show records".
                05 LINE 11 COLUMN 1  VALUE "       5) Create new file".
                05 LINE 13 COLUMN 1  VALUE "       0) Exit".
                05 LINE 15 COLUMN 1  VALUE "             Choice? ".
                05 LINE 15 COLUMN 25 PICTURE X(30) FROM Error-Msg FOREGROUND-COLOR 4.
                05 LINE 24 COLUMN 1  VALUE " (c) YvanSoftware ".
        01  InvoerMenu.
                05 BLANK SCREEN.
                05 LINE 1  COLUMN 1  VALUE " CAddress - A COBOL Address Book".
                05 LINE 2  COLUMN 1  VALUE " -------------------------------".
                05 LINE 4  COLUMN 1  VALUE "   Input Data".
                05 LINE 5  COLUMN 1  VALUE "   ~~~~~~~~~~".
                05 LINE 7  COLUMN 1  VALUE "   First name   :" FOREGROUND-COLOR 2.
                05 LINE 8  COLUMN 1  VALUE "   Last name    :" FOREGROUND-COLOR 2.
                05 LINE 9  COLUMN 1  VALUE "   Address      :" FOREGROUND-COLOR 2.
                05 LINE 10 COLUMN 1  VALUE "   City         :" FOREGROUND-COLOR 2.
                05 LINE 11 COLUMN 1  VALUE "   ZIP          :" FOREGROUND-COLOR 2.
                05 LINE 12 COLUMN 1  VALUE "   Country      :" FOREGROUND-COLOR 2.
                05 LINE 13 COLUMN 1  VALUE "   Telephone    :" FOREGROUND-COLOR 2.
                05 LINE 15 COLUMN 1  VALUE "       Save? y(es)/n(o)/c(orrect) " FOREGROUND-COLOR 4.
                05 LINE 24 COLUMN 1  VALUE " (c) YvanSoftware ".
        01  UitvoerScherm.
                05 BLANK SCREEN.
                05 LINE 1  COLUMN 1  VALUE " CAddress - A COBOL Address Book".
                05 LINE 2  COLUMN 1  VALUE " -------------------------------".
                05 LINE 4  COLUMN 1  VALUE "   Find Data".
                05 LINE 5  COLUMN 1  VALUE "   ~~~~~~~~~~".
                05 LINE 7  COLUMN 1  VALUE "   First name   :" FOREGROUND-COLOR 2.
                05 LINE 8  COLUMN 1  VALUE "   Last name    :" FOREGROUND-COLOR 2.
                05 LINE 9  COLUMN 1  VALUE "   Address      :" FOREGROUND-COLOR 2.
                05 LINE 10 COLUMN 1  VALUE "   City         :" FOREGROUND-COLOR 2.
                05 LINE 11 COLUMN 1  VALUE "   ZIP          :" FOREGROUND-COLOR 2.
                05 LINE 12 COLUMN 1  VALUE "   Country      :" FOREGROUND-COLOR 2.
                05 LINE 13 COLUMN 1  VALUE "   Telephone    :" FOREGROUND-COLOR 2.
* Col 45 Input
                05 LINE 15 COLUMN 1  VALUE "         Navigate? n(ext)/p(revious)/x(exit) " FOREGROUND-COLOR 4.
                05 LINE 24 COLUMN 1  VALUE " (c) YvanSoftware ".
        01  FoutScherm.
                05 BLANK SCREEN.
                05 LINE 4  COLUMN 15 VALUE "====================(ERROR)======================" BACKGROUND-COLOR 4 FOREGROUND-COLOR 7.
                05 LINE 5  COLUMN 15 VALUE "                                                 " BACKGROUND-COLOR 4 FOREGROUND-COLOR 7.
                05 LINE 6  COLUMN 15 VALUE "                                                 " BACKGROUND-COLOR 4 FOREGROUND-COLOR 7.
                05 LINE 7  COLUMN 15 VALUE "                                                 " BACKGROUND-COLOR 4 FOREGROUND-COLOR 7.
                05 LINE 8  COLUMN 15 VALUE "                                                 " BACKGROUND-COLOR 4 FOREGROUND-COLOR 7.
                05 LINE 10 COLUMN 15 VALUE "                INPUT C TO CONTINUE              " BACKGROUND-COLOR 4 FOREGROUND-COLOR 7.
                05 LINE 6  COLUMN 18 PICTURE X(45) FROM Error-screen-msg BACKGROUND-COLOR 4 FOREGROUND-COLOR 7 BLINK.
 PROCEDURE DIVISION.      
  main.
        PERFORM Show-MainMenu UNTIL menu-invoer-afsluiten.
        STOP RUN.
     .
  Show-MainMenu.
        DISPLAY MainMenu
        ACCEPT menu-hoofd-invoer LINE 15 COLUMN 22.
        IF menu-invoer-incorrect
        THEN
                MOVE " Incorrect input" TO Error-Msg
                MOVE " " TO Green-Msg
        END-IF.
        IF menu-invoer-record-toevoegen
        THEN
                PERFORM Show-InvoerMenu
        END-IF
        IF menu-invoer-nieuw-bestand
        THEN
                PERFORM Show-NewFile
        END-IF.
     .
  Show-InvoerMenu.
        DISPLAY InvoerMenu.
        ACCEPT user-first-name      LINE 7  COLUMN 18
                WITH FOREGROUND-COLOR 4.
        ACCEPT user-last-name       LINE 8  COLUMN 18
                WITH FOREGROUND-COLOR 4.
        ACCEPT user-address         LINE 9  COLUMN 18
                WITH FOREGROUND-COLOR 4.
        ACCEPT user-city            LINE 10 COLUMN 18
                WITH FOREGROUND-COLOR 4.
        ACCEPT user-zip             LINE 11 COLUMN 18
                WITH FOREGROUND-COLOR 4.
        ACCEPT user-country         LINE 12 COLUMN 18
                WITH FOREGROUND-COLOR 4.
        ACCEPT user-telephone       LINE 13 COLUMN 18
                WITH FOREGROUND-COLOR 4.

        PERFORM AskForSave.
  .
  Show-NewFile.
        DISPLAY InvoerMenu.
        ACCEPT user-first-name      LINE 7  COLUMN 18
                WITH FOREGROUND-COLOR 4.
        ACCEPT user-last-name       LINE 8  COLUMN 18
                WITH FOREGROUND-COLOR 4.
        ACCEPT user-address         LINE 9  COLUMN 18
                WITH FOREGROUND-COLOR 4.
        ACCEPT user-city            LINE 10 COLUMN 18
                WITH FOREGROUND-COLOR 4.
        ACCEPT user-zip             LINE 11 COLUMN 18
                WITH FOREGROUND-COLOR 4.
        ACCEPT user-country         LINE 12 COLUMN 18
                WITH FOREGROUND-COLOR 4.
        ACCEPT user-telephone       LINE 13 COLUMN 18
                WITH FOREGROUND-COLOR 4.

        PERFORM AskForSaveNew.

  AskForSave.  
        ACCEPT Yes-No-Correct-Field LINE 15 COLUMN 35
                WITH FOREGROUND-COLOR 2.

        IF Yes-No-Field-Correct
        THEN
                PERFORM Show-InvoerMenu
        END-IF.

        IF Yes-No-Field-No
        THEN
                PERFORM Show-MainMenu
        END-IF.

        IF Yes-No-Field-Yes
        THEN
                PERFORM Save-Record
        END-IF.

        IF NOT Yes-No-Field-No AND NOT Yes-No-Field-Yes AND NOT Yes-No-Field-Correct
        THEN
                PERFORM AskForSave
        END-IF.
        .
  Save-Record.
        OPEN I-O TelephoneBookFile.
        PERFORM AddRecordKey.
        MOVE user-first-name TO user-record-first-name.
        MOVE user-last-name  TO user-record-last-name .
        MOVE user-address    TO user-record-address   .
        MOVE user-city       TO user-record-city      .
        MOVE user-zip        TO user-record-zip       .
        MOVE user-country    TO user-record-country   .
        MOVE user-telephone  TO user-record-telephone .
        WRITE User-Record-File INVALID KEY PERFORM ExistsAlready.
        CLOSE TelephoneBookFile
        .
  AskForSaveNew.       
        ACCEPT Yes-No-Correct-Field LINE 15 COLUMN 35
                WITH FOREGROUND-COLOR 2.

        IF Yes-No-Field-Correct
        THEN
                PERFORM Show-NewFile
        END-IF.

        IF Yes-No-Field-No
        THEN
                PERFORM Show-MainMenu
        END-IF.

        IF Yes-No-Field-Yes
        THEN
                PERFORM Save-Record-NewFile
        END-IF.

        IF NOT Yes-No-Field-No AND NOT Yes-No-Field-Yes AND NOT Yes-No-Field-Correct
        THEN
                PERFORM AskForSave
        END-IF.
        .
  Save-Record-NewFile.
                OPEN OUTPUT TelephoneBookFile.
                PERFORM AddRecordKey.

        MOVE user-first-name TO user-record-first-name.
        MOVE user-last-name  TO user-record-last-name .
        MOVE user-address    TO user-record-address   .
        MOVE user-city       TO user-record-city      .
        MOVE user-zip        TO user-record-zip       .
        MOVE user-country    TO user-record-country   .
        MOVE user-telephone  TO user-record-telephone .
        WRITE User-Record-File.
        CLOSE TelephoneBookFile.
        .
  AddRecordKey.
        STRING user-first-name(1:5) user-last-name(1:5)
                   user-address(1:5) user-city(1:5)
                   user-zip(1:5) user-country(1:5)
                   user-telephone(1:5)
                DELIMITED BY SIZE
                INTO user-record-key
        .
  ExistsAlready.
        MOVE "Record already exists" TO Error-Screen-Msg
        PERFORM ErrorScreen
      .
  ErrorScreen.
        DISPLAY FoutScherm
        ACCEPT  Error-Continue-Flag LINE 24 COLUMN 80
        IF NOT Error-Continue-OK
        THEN
                Perform ErrorScreen
        END-IF.
        .  
 END PROGRAM CAddress.

I'm getting a weird COBOL Error, and I couldn't find what it means.
It says Open Error (see the following screenshot).

It doesn't occur if I first use "new file", and add a record after that.

Here's the application binary and some log files it produced.

Many thanks,

Yvan

PS: It's Fujitsu NetCobol dialect.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

热风软妹 2024-09-18 07:47:51

我想了解有关您所遇到的文件 I/O 问题的更多信息
拥有。如果我理解正确,您可以毫无问题地执行以下操作:

  • 创建新文件
  • 添加记录
  • 退出

然后,如果您再次启动程序并立即

  • 添加记录

,则程序炸弹会出现“奇怪的错误”。

你可以阅读吗
并显示您在初始运行中编写的记录?我想知道之前是否
写入成功,这反过来又使文件的完整性受到质疑。

我建议探索 SELECTOPTIONAL 关键字,并
还添加一个 FILE STATUS 子句。应检查文件状态
每次 I/O 操作(OPEN、CLOSE、WRITE、READ 等)之后。包含的值
在与FILE STATUS关联的变量中将带你走很长的路
以解决问题。以下表格
描述文件状态值。

您可能还想查看此教程
处理 COBOL 中的索引文件。

我可能还没弄清楚你的文件 I/O 问题是什么,但我确实明白了
以后肯定会带来麻烦的其他事情!

您使用了以下构造:

PERFORM Some-Paragraph
...
Some-Paragraph.
...
IF Some-Condition
   PERFORM Some-Paragraph
END-IF
.

最后一个 PERFORM Some-Paragraph 在范围内
段落本身。 COBOL 编译器可能不会将此标记为错误,但
行为未定义。 COBOL PERFORM 不符合
到您可能熟悉的 CALL/RETURN 语义
其他语言。您在这里编写的代码通常称为
作为“逻辑炸弹”。我所指的详细描述可以
可以在此处找到。

I would like to have a bit more information on the file I/O problem you are
having. If I understand correctly, you can do the following without problem:

  • Create new file
  • Add record
  • Exit

Then if you start the program again and immediately

  • Add record

the program bombs with a "weird error".

Is it possible for you to read
and display the record you wrote in the initial run? I am wondering if the prior
write was successful, which in turn brings into question the integrity of the file.

I would suggest exploring the OPTIONAL keyword for SELECT and
adding a FILE STATUS clause too. The file status should be checked
after each I/O operation (OPEN, CLOSE, WRITE, READ etc.). The value contained
in the variable associated with FILE STATUS will take you a long way
toward sorting out the problem. The following table
describes FILE STATUS values.

You might also want to review this tutorial on
processing indexed files in COBOL.

I may not have figured out what your file I/O problem is but I do see
something else that is bound to cause trouble later on!

You have used the following construct:

PERFORM Some-Paragraph
...
Some-Paragraph.
...
IF Some-Condition
   PERFORM Some-Paragraph
END-IF
.

The last PERFORM Some-Paragraph is within the scope of
the paragraph itself. COBOL compilers may not flag this as an error but the
behaviour is undefined. COBOL PERFORM does not conform
to the CALL/RETURN semantics that you may be familiar with from
other languages. What you have coded here is commonly known as
as 'Logic Bomb'. A detailed description of what I am referring to can
be found here.

笑梦风尘 2024-09-18 07:47:51

也许程序会在创建文件之前尝试访问该文件。 “新文件”选项可能会使用 OPEN OUTPUT 语句创建数据文件,并且添加记录将会成功。

Perhaps the the program tries to access the file before it is created. The 'new file' option probably creates the data file with the OPEN OUTPUT statement and adding a record will succeed.

晌融 2024-09-18 07:47:51

第一个错误可能是文件状态错误 35,打开的文件不存在。
您应该重构您的代码。在数据输入程序中,您只需要 OPEN 和 CLOSE
每次执行一次的语句。
在此程序中,OPEN 语句应尽可能放置在靠近源代码开头的位置(为了在开头执行一次,以及为了可读性),而 CLOSE 语句应位于 STOP RUN 之前。

The first error is probably a file status error 35, opening a file that does not exist.
You should restructure your code. In a data entry program you only need the OPEN and CLOSE
statements to be executed once each time.
In this program the OPEN statement should be placed as near as possible to the beginning of the source code (to execute once at the beginning, as well as for readability) and the CLOSE should be just before the STOP RUN.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文