COBOL:当两者都有返回码10时,如何区分文件结尾和垃圾值? [英] COBOL: How to differentiate between end of file and junk value when both have return code 10?

查看:136
本文介绍了COBOL:当两者都有返回码10时,如何区分文件结尾和垃圾值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Fujitsu COBOL,有时会不得不读取文件,并且如果有垃圾值,则我想放弃工作。

I am working on Fujitsu COBOL and there is a situation where I have to read the file and if there is a junk value then I want to abend the job.

如果有垃圾值,则返回码为10,但要注意的是,即使有EOF(文件末尾),返回码也为10。

When there is a junk value the return code is 10 but the catch is that when there is EOF (end of file) even then the return code is 10.

推荐答案

在非常早的PC上(MS-在DOS 1.0中,将Ctrl + Z(X 1A)用作文本文件的文件结尾。您的编译器可能会检测到该字符并将其视为文件的结束,而不是允许处理文件的其余部分。

On very early PCs (MS-DOS 1.0), a Ctrl+Z (X"1A") was used as end-of-file for text files. Your compiler is likely detecting that character and treating it as end-if-file instead of allowing the remainder of the file to be processed.

在OEM / DOS字符集中,X 1A显示为向右箭头。 (您在评论中提到了一个箭头。)我创建了一个短文件,其中包含用于测试的四个记录。

In the OEM/DOS character set, X"1A" appears as a right-pointing arrow. (You mentioned an arrow in a comment.) I created a short file with four records for testing.

原始文件:

Record1
Record2
Record3
Record4

我用X 1A替换了 3。在十六进制编辑器中,它显示为

I replaced the "3" with X"1A". In a hex editor, it appears as,

请注意,x 1A字符显示为向右箭头。

Notice that the x"1A" character appears as a right-pointing arrow.

A编写了一个程序(未显示)来读取显示文件的输出。

A wrote a program (not shown) to read the file displaying the output of the modified file.

Record1
Record2
Record
0003 lines read

文件结尾出现在X 1A。

End of file occurred at the X"1A".

下面的程序可用于检查X 1A和确定损坏的记录的出现...,以便[您]可以更正文件。

The following program may be used to check for X"1A" and "identify the corrupt record occurrence ... so that [you] can correct the file".

   program-id. ctrl-z.
   environment division.
   input-output section.
   file-control.
       select in-file assign "ctrl-z.txt"
           organization sequential
       .
   data division.
   file section.
   fd in-file.
   1 in-char pic x.
   working-storage section.
   1 line-count binary pic 9(4) value 0.
   1 msg-txt pic x(25) value "lines read".
     88 error-msg value "lines read before cntrl-z".
   1 eof-in-file-flag pic 9 value 0.
     88 eof-in-file value 1.
   procedure division.
   begin.
       open input in-file
       read in-file
           at end set eof-in-file to true
       end-read
       perform until eof-in-file
           evaluate in-char
           when x"0A"
               add 1 to line-count
           when x"1A"
               set error-msg to true
               set eof-in-file to true
               exit perform
           when other
               continue
           end-evaluate
           read in-file
               at end set eof-in-file to true
           end-read
       end-perform
       close in-file
       display line-count space msg-txt
       stop run
       .
   end program ctrl-z.

结果是:

0002 lines read before cntrl-z

这篇关于COBOL:当两者都有返回码10时,如何区分文件结尾和垃圾值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆