我正在尝试写入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
。