因为在SEQUENTIAL访问模式下,只有I/O方式打开文件才能进行REWRITE操作,所以以下文件均用I/O方式打开。
FILE-CONTROL.
SELECT VFILE ASSIGN TO VF
ORGANIZATION IS INDEXED
ACCESS MODE IS SEQUENTIAL
RECORD KEY IS VID
FILE STATUS IS FS1.
DATA DIVISION.
FILE SECTION.
FD VFILE.
01 VREC.
05 VID PIC X(4).
05 VINFO PIC X(76).
WORKING-STORAGE SECTION.
01 FS1 PIC 99.
01 REC PIC X(80).
01 FLAG PIC X.
PROCEDURE DIVISION.
OPEN I-O VFILE.
DISPLAY FS1.
MOVE 0444 TO VID.
MOVE '0444D02APPLE' TO REC.
START VFILE KEY IS = VID.
READ VFILE
END-READ.
REWRITE VREC FROM REC
END-REWRITE.
DISPLAY FS1.
IF FS1 = 00
THEN
DISPLAY 'THE RECORD IS ', VREC
END-IF.
CLOSE VFILE.
STOP RUN.
总结
SEQUENTIAL三步曲:
1.start
2.read(因为rewrite之前必须read,不然就返回码43,而要想read指定记录就需要先start定位到指定的位置上,所以……)
3.rewrite……from……(from也是必须的,这是逻辑上的需要,相信聪明的童靴都会懂的) 或者 delete……