cobol中的write问题

2025-01-05 06:19:31
推荐回答(1个)
回答1:

DATA DIVISION.
FILE SECTION.
FD READFILE LABEL RECORD IS OPEN-R,OPEN-S.
01 OPEN-R.
02 OPEN-FIR PIC X(6).
02 OPEN-SEC PIC X(6).
02 OPEN-THR PIC X(6).
01 OPEN-S PIC X(5).

WORKING-STORAGE SECTION.
01 CNT PIC 9(2).

PROCEDURE DIVISION.

MOVE SPACE TO OPEN-R.
MOVE SPACE TO OPEN-S.
MOVE ZERO TO CNT.

MOVE 'NEWORD' TO OPEN-FIR.
MOVE 'SECOND' TO OPEN-SEC.
MOVE 'THRIDE' TO OPEN-THR.

OPEN EXTEND READFILE.
PERFORM VARYING CNT FROM 1 BY 1
UNTIL CNT IS GREATER THAN 10
IF CNT < 10
THEN
WRITE OPEN-R AFTER ADVANCING 1 LINES
ELSE
CONTINUE
END-IF
END-PERFORM.
MOVE 'YUMEN' TO OPEN-S.
WRITE OPEN-S AFTER ADVANCING 1 LINES
CLOSE READFILE.

你 DF 那 有两个 01 层 可能有重定义的 可能,两个 01层 共享的 同一内存地址,所以 赋值进去 会覆盖

我给你稍微改了改 你看看 这样行不行,注意以后写程序的时候 初始化 很重要,记得 在 用到之前 初始化一下 你的变量!~