扩展开放 (COBOL)

发布于 2024-10-17 21:23:49 字数 1247 浏览 1 评论 0原文

我最近接到一项任务,要求使用“EXTEND OPEN”命令将数据添加到现有文件中。虽然我以为我明白它的作用,但我发现我的程序遇到了障碍,给我这个错误:“148 错误的打开模式或写入访问模式”。这是一个简单的程序,旨在仅将一个新的条目文件添加到主文件中,但我不太明白它。这就是我所拥有的:

   DATA DIVISION.
   FILE SECTION.

   FD  OLD-MASTER-IN.
   01  OLD-MASTER-REC-IN.
       05  O-STATE-ABREV-IN                PIC XX.
       05                                  PIC X.
       05  O-STATE-NAME-IN                 PIC X(17).

   FD  TRANS-FILE-IN.
   01  TRANS-REC-IN.
       05  N-STATE-ABREV-IN                PIC XX.
       05                                  PIC X.
       05  N-STATE-NAME-IN                 PIC X(17).

   WORKING-STORAGE SECTION.
   01  ARE-THERE-MORE-RECORDS              PIC X(3)  VALUE 'YES'.

   PROCEDURE DIVISION.
   100-MAIN.
       OPEN INPUT OLD-MASTER-IN
            EXTEND TRANS-FILE-IN

       PERFORM UNTIL ARE-THERE-MORE-RECORDS = 'NO '
           READ OLD-MASTER-IN
               AT END
                   MOVE 'NO' TO ARE-THERE-MORE-RECORDS
               NOT AT END
                   PERFORM 200-REGULAR-UPDATE
           END-READ
       END-PERFORM

       CLOSE OLD-MASTER-IN
             TRANS-FILE-IN
       STOP RUN.

   200-REGULAR-UPDATE.
       WRITE OLD-MASTER-REC-IN FROM TRANS-REC-IN.

任何帮助将不胜感激。

I recently got an assignment to use the "EXTEND OPEN" command to add data to an already existing file. While I thought I understood what it did I find that my program is hitting a snag, giving me this error: "148 Wrong open mode or access mode for write". It is a simple program, meant to only add one new file of entries to a master file, but I can't quite get it. Here is what I have:

   DATA DIVISION.
   FILE SECTION.

   FD  OLD-MASTER-IN.
   01  OLD-MASTER-REC-IN.
       05  O-STATE-ABREV-IN                PIC XX.
       05                                  PIC X.
       05  O-STATE-NAME-IN                 PIC X(17).

   FD  TRANS-FILE-IN.
   01  TRANS-REC-IN.
       05  N-STATE-ABREV-IN                PIC XX.
       05                                  PIC X.
       05  N-STATE-NAME-IN                 PIC X(17).

   WORKING-STORAGE SECTION.
   01  ARE-THERE-MORE-RECORDS              PIC X(3)  VALUE 'YES'.

   PROCEDURE DIVISION.
   100-MAIN.
       OPEN INPUT OLD-MASTER-IN
            EXTEND TRANS-FILE-IN

       PERFORM UNTIL ARE-THERE-MORE-RECORDS = 'NO '
           READ OLD-MASTER-IN
               AT END
                   MOVE 'NO' TO ARE-THERE-MORE-RECORDS
               NOT AT END
                   PERFORM 200-REGULAR-UPDATE
           END-READ
       END-PERFORM

       CLOSE OLD-MASTER-IN
             TRANS-FILE-IN
       STOP RUN.

   200-REGULAR-UPDATE.
       WRITE OLD-MASTER-REC-IN FROM TRANS-REC-IN.

Any Help will be appreciated.

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

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

发布评论

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

评论(2

灼疼热情 2024-10-24 21:23:49

我想通了。我现在真是傻了。看来我扩展/读取了错误的文件。愚蠢的我。该代码应该如下所示:

   PROCEDURE DIVISION.
   100-MAIN.
       OPEN INPUT TRANS-FILE-IN
            EXTEND OLD-MASTER-IN

       PERFORM UNTIL ARE-THERE-MORE-RECORDS = 'NO '
           READ TRANS-FILE-IN
               AT END
                   MOVE 'NO' TO ARE-THERE-MORE-RECORDS
               NOT AT END
                   PERFORM 200-REGULAR-UPDATE
           END-READ
       END-PERFORM

       CLOSE TRANS-FILE-IN
             OLD-MASTER-IN
       STOP RUN.

   200-REGULAR-UPDATE.
       WRITE OLD-MASTER-REC-IN FROM TRANS-REC-IN.

I figured it out. I really stupid now. Seems I extended/read the wrong file. Silly me. The code is suppose to look like this:

   PROCEDURE DIVISION.
   100-MAIN.
       OPEN INPUT TRANS-FILE-IN
            EXTEND OLD-MASTER-IN

       PERFORM UNTIL ARE-THERE-MORE-RECORDS = 'NO '
           READ TRANS-FILE-IN
               AT END
                   MOVE 'NO' TO ARE-THERE-MORE-RECORDS
               NOT AT END
                   PERFORM 200-REGULAR-UPDATE
           END-READ
       END-PERFORM

       CLOSE TRANS-FILE-IN
             OLD-MASTER-IN
       STOP RUN.

   200-REGULAR-UPDATE.
       WRITE OLD-MASTER-REC-IN FROM TRANS-REC-IN.
撩心不撩汉 2024-10-24 21:23:49

如果您使用现代编译器编写代码,那么您的代码可能看起来不像是在 70 年代编写的。

以下是您可以执行的操作的示例:

OPEN INPUT TRANS-FILE-IN
OPEN EXTENT OLD-MASTER-IN

PERFORM UNTIL EXIT
    READ TRANS-FILE-IN
        AT END
        EXIT PERFORM
    END-READ
    WRITE OLD-MASTER-REC-IN FROM TRANS-REC-IN
END-PERFORM

CLOSE TRANS-FILE-IN
CLOSE OLD-MASTER-IN

当然,这里没有错误检查,但这是一个很大的主题。

If you are writing with a modern compiler your code could be written to not look like it was written in the 70's.

Here is an example of what you could do:

OPEN INPUT TRANS-FILE-IN
OPEN EXTENT OLD-MASTER-IN

PERFORM UNTIL EXIT
    READ TRANS-FILE-IN
        AT END
        EXIT PERFORM
    END-READ
    WRITE OLD-MASTER-REC-IN FROM TRANS-REC-IN
END-PERFORM

CLOSE TRANS-FILE-IN
CLOSE OLD-MASTER-IN

Of course, there is no error checking in here but that is a large topic.

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