COBOL 程序不写入文件
大家好,
我有一个 DISP = (MOD, CATLG, CATLG) 的顺序文件 我的程序执行 OPEN IO,它应该写入文件 但是,当作业成功结束时,文件仍然是空的..
我错过了什么吗?
FILE
REJECT DD DSN=FILEA,
DISP=(MOD,CATLG,CATLG),UNIT=TESTPACK,
DCB=(LRECL=109,BLKSIZE=0,RECFM=FB),
SPACE=(TRK,(3,1),RLSE)
COBOL Program:
FD REJECT-FILE
RECORDING MODE IS F
LABEL RECORDS ARE STANDARD
BLOCK CONTAINS 0 RECORDS
RECORD CONTAINS 109 CHARACTERS
DATA RECORD IS REJC-OUT-RECORD.
01 REJC-OUT-RECORD PIC X(109).
ADD-REJECTS-HEADER.
SKIP1
READ REJECT-FILE INTO RECORD-IN
EVALUATE WS-STATUS
WHEN '00'
CONTINUE
WHEN '10'
CLOSE REJECT-FILE
OPEN I-O REJECT-FILE
WRITE REJC-OUT-RECORD FROM WS-HEADER-REJ
END-EVALUATE.
HI all,
I have a sequential file with DISP = (MOD, CATLG, CATLG)
My program does an OPEN I-O and it is supposed to write to the file
however, when job ends successfully, the file is still empty..
am i missing something?
FILE
REJECT DD DSN=FILEA,
DISP=(MOD,CATLG,CATLG),UNIT=TESTPACK,
DCB=(LRECL=109,BLKSIZE=0,RECFM=FB),
SPACE=(TRK,(3,1),RLSE)
COBOL Program:
FD REJECT-FILE
RECORDING MODE IS F
LABEL RECORDS ARE STANDARD
BLOCK CONTAINS 0 RECORDS
RECORD CONTAINS 109 CHARACTERS
DATA RECORD IS REJC-OUT-RECORD.
01 REJC-OUT-RECORD PIC X(109).
ADD-REJECTS-HEADER.
SKIP1
READ REJECT-FILE INTO RECORD-IN
EVALUATE WS-STATUS
WHEN '00'
CONTINUE
WHEN '10'
CLOSE REJECT-FILE
OPEN I-O REJECT-FILE
WRITE REJC-OUT-RECORD FROM WS-HEADER-REJ
END-EVALUATE.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要在“写入”后“关闭”拒绝文件。
此外,还有比“00”和“10”更多的可能条件代码。
我建议您将“WHEN '10'”替换为“OTHERWISE”以捕获所有非零条件。
You need to "CLOSE" the REJECT-FILE after your "WRITE".
Also there are many more possible condition codes than '00' and '10'.
I would suggest you replace the "WHEN '10'" with " OTHERWISE" to catch all non zero conditions.
为了使程序在文件操作方面“更安全”,您应该做的几件事是:
1)检查每个文件操作的
FILE-STATUS
并做出反应,OPEN、READ、写入并关闭。2) 为意外情况提供全面的解决方案。您
仅检查“正常”和“文件结束”条件。还可能表明许多其他事情。请参阅 此参考。
看起来您可能正在尝试读取和写入同一个物理文件。所有 I/O 操作(OPEN/READ/WRITE)都引用同一个文件。您是否尝试打开文件进行顺序访问,并在到达文件末尾时切换到 IO 然后添加
新纪录?
如果您也显示
FILE-CONTROL
段落,将会非常有帮助。这将指示您尝试访问该文件的方式。我认为FILE-CONTROL
下指定的访问模式以及PROCEDURE DIVISION
中的OPEN/CLOSE/READ和WRITE可能存在问题。例如,我没有看到您在哪里为IO
写入操作指定记录键。提供
FILE-CONTROL
段落并告诉我们更多有关该程序正在执行的操作的信息。另外,请给我们 FILE-STATUS 的值,届时我们可能可以提供更多帮助。A couple of things you should to do to make your program a bit "safer" with respect to file operations are:
1) Check and react to the
FILE-STATUS
on every file operation, OPEN, READ, WRITE and CLOSE.2) Provide a catch-all for unexpected conditions. You
are only checking for "normal" and "end-of-file" conditions. A lot of other things might be indicated as well. See this reference.
It looks like you may be trying to read from and write to the same physical file. All of the I/O operations (OPEN/READ/WRITE) refer to the same file. Are you attempting to open the file for sequential access and upon reaching the end-of-file, switch to I-O then add
a new record?
It would be very helpful if you showed the
FILE-CONTROL
paragraph as well. This will indicate how you are trying to access the file. I think there may be problems with the access mode specified underFILE-CONTROL
and the OPEN/CLOSE/READ and WRITEs in thePROCEDURE DIVISION
. For example, I don't see where you are specifying the record key for theI-O
write operation.Provide the
FILE-CONTROL
paragraph and tell us a bit more about what this program is doing. Also, give us the value ofFILE-STATUS
we might be able to offer more help at that point.该文件曾经被打开过吗?如果您刚刚用 MOD 重新分配它,它将没有正确的 EOF 标记。有时您会看到人们使用 IEBGENER 分配新数据集并为其复制 0 条记录以写入 EOF 标记。
Has the file EVER been opened? If you just freshly allocated it with MOD, it will not have a proper EOF marker. Sometimes you will see people use IEBGENER to allocate NEW datasets an copy 0 records to them to get the EOF marker written.