我想在一个文件里写入一些记录,代码如下:
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 'NEWORD' TO OPEN-FIR.
MOVE 'SECOND' TO OPEN-SEC.
MOVE 'THRIDE' TO OPEN-THR.
MOVE 'YUMEN' TO OPEN-S.
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.
WRITE OPEN-S AFTER ADVANCING 1 LINES
CLOSE READFILE.
其他地方和这里关系不大,所以没贴上来,我得到的文件内容却是这样的:
YUMENDSECONDTHRIDE
YUMENDSECONDTHRIDE
YUMENDSECONDTHRIDE
YUMENDSECONDTHRIDE
YUMENDSECONDTHRIDE
YUMENDSECONDTHRIDE
YUMENDSECONDTHRIDE
YUMENDSECONDTHRIDE
YUMENDSECONDTHRIDE
YUMEN
其实我想得到的是:
NEWORDSECONDTHRIDE
NEWORDSECONDTHRIDE
NEWORDSECONDTHRIDE
NEWORDSECONDTHRIDE
NEWORDSECONDTHRIDE
NEWORDSECONDTHRIDE
NEWORDSECONDTHRIDE
NEWORDSECONDTHRIDE
NEWORDSECONDTHRIDE
YUMEN
我认为这个程序的逻辑会得到我想要的格式啊 为什么open-r的一部分内容会被open-s的内容覆盖了呢?请帮忙看看,谢谢了!!!
------解决方案--------------------------------------------------------
变量在用的时候没有初始化吧?
------解决方案--------------------------------------------------------
检查变量,应该是初始化问题。