逐行读取由换行符分隔的cobol文件

Reading cobol file line by line seperated by new line character

我无法逐行读取文件。这是代码的当前片段:

file-control.
    select input-file
    assign input-file-name
    organization is sequential
file section.
    fd input-file.
    01 input-file-record picturex(25)
working-storage section.
01 ws-eof picture a(1).

这是我在文件中实际阅读的位置:

perform until ws-eof = 'Y'
    read input-file into input-file-record
    at end move 'Y' to ws-eof
    not at end
        display input-file-record
    end-read
end-perform
    close input-file

问题是,我试图逐行读取文件,但它似乎只填满了 25 个字符,然后再次读取而不是循环读取文本文件中的 return 字符.

文本文件看起来像这样:

AAAA
BBBB
CCCC
DDDD

The problem is, i'm trying to read the file line by line, but it seems like it's just filling up 25 characters, then reading again instead of looping by the return character in the text file.

系统完全按照您的指示执行:

organization is sequential             *>  sequential, fixed length
01 input-file-record picture x(25)     *>  the fixed length is 25 bytes

取决于您使用的编译器(如果还没有您可以使用的特定标记,最好指定它,即使在这种情况下,版本号也不会造成伤害)您可以要么使用通用扩展(可能甚至成为 COBOL 202x 的标准):

organization is line sequential        *>  sequential, read until line break found

或者必须按顺序阅读(在这种情况下可能有更大的尺寸)和

检查 file-rec 将所有 x'0d' 转换为 x'0a' *> 如果您期望 windows 或 mac 换行符 移动 1 到 strpoint 解串 file-rec 由所有 x'0a' 分隔 进入 real-rec 带指针 strpoint end-unstring