在COBOL中写入索引文件的文件状态为48

问题描述 投票:0回答:1

我正在尝试在COBOL程序中写索引文件(具体来说是GnuCOBOL),但是它给我的是文件状态48,这意味着已经尝试对不在输出IO中的文件进行写操作,或扩展模式,或处于顺序访问模式的文件上。该文件处于随机访问模式,我以I-O格式打开了文件,因此我不知道自己可能做错了什么。我尝试删除记录时发生类似的问题(错误47)。我在网上搜索过,似乎没有人遇到此问题。

输入输出部分说:

        Select Infile
        Assign to "lab9-upsert.dat"
        Organization is Line Sequential.
        Select Master-File
        Assign to "lab9b-master.dat"
        Organization is Indexed
        Access Mode is Random
        Record Key is Master-MovieNum
        Status is FileStatus.

在文件部分:

   FD Infile.
   01 In-Record.
        05 In-MovieNum          Pic 9(5).
        05 In-MovieName         Pic X(50).
        05 In-MovieGenre        Pic X(20).    

   FD Master-File.
   01 Master-Record.
        05 Master-MovieNum      Pic 9(5).
        05 Master-MovieName     Pic X(50).
        05 Master-MovieGenre    Pic X(20).

并且我尝试的编写功能如下(显示语句用于调试):

        Start Master-File
        Move "N" To IsAtEnd *> variable defined in working storage, EndOfFile is a condition name for when IsAtEnd is "Y"

        Perform Until EndOfFile
            Read Infile
                At End
                    Move "Y" To IsAtEnd
                Not At End
                    Move In-Record To Master-Record

                    Display "Movie number: " Master-MovieNum
                    Write Master-Record
                    Evaluate FileStatus
                        When 0
                            Display "Successful write!"
                        When 22
                            If In-MovieName <> Spaces
                                Move In-MovieName
                                To Master-MovieName
                            End-If
                            If In-MovieGenre <> Spaces
                                Move In-MovieGenre
                                To Master-MovieGenre
                            End-If
                            Rewrite Master-Record
                            Display "Successful rewrite!"
                        When Other
                            Display "Upsert Error " FileStatus
                    End-Evaluate
            End-Read
        End-Perform

我真的很需要完成这项任务,而我在这方面完全迷失了。

编辑:我想现在已经知道了。我需要在程序的第一次运行时将Select Master-File更改为Select Optional Master-File

cobol
1个回答
0
投票

似乎您的I-O操作无法正常工作,对此文件执行打开操作后您是否正在检查FileStatus变量?

© www.soinside.com 2019 - 2024. All rights reserved.