在下面的程序中,我执行与索引文件的基本交互。当我尝试添加记录时,一切都按预期工作,我什至收到成功消息。但是,当读取它的代码lees
--试图找到对应的ID时,它找不到它。当我查看磁盘上索引文件的大小时,我可以看到它的大小为 0kb。我在看什么?
000100 IDENTIFICATION DIVISION.
000200 PROGRAM-ID. oef16_indexedfiles.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT indexfile ASSIGN TO "C:\Test\indexedfile.dat"
ORGANIZATION IS INDEXED
ACCESS IS DYNAMIC
RECORD KEY IS id-number
ALTERNATE KEY IS fname WITH DUPLICATES
ALTERNATE KEY IS lname WITH DUPLICATES
ALTERNATE KEY IS city WITH DUPLICATES
ALTERNATE KEY IS hobby WITH DUPLICATES.
DATA DIVISION.
FILE SECTION.
FD indexfile.
01 persoon.
02 id-number PIC 9.
02 name.
03 fname PIC A(25).
03 lname PIC A(30).
02 city PIC A(30).
02 hobby PIC X(40).
WORKING-STORAGE SECTION.
01 einde PIC X.
01 msg PIC X(50).
01 countno PIC 9 VALUE 1.
PROCEDURE DIVISION.
PGM.
PERFORM schrijf
PERFORM lees
STOP RUN.
check.
DISPLAY msg
ACCEPT einde
schrijf.
MOVE "1 = stoppen, 0 = doorgaan" TO msg
PERFORM check
OPEN I-O indexfile
PERFORM UNTIL einde = 1
MOVE countno TO id-number
DISPLAY "Enter your first name:"
ACCEPT fname
DISPLAY "Enter your last name:"
ACCEPT lname
DISPLAY "Enter your city:"
ACCEPT city
DISPLAY "Enter your hobby:"
ACCEPT hobby
WRITE persoon
INVALID KEY
DISPLAY "ERROR WRITING: " id-number
NOT INVALID KEY
DISPLAY "ID " id-number " by " fname " is added"
END-WRITE
ADD 1 TO countno
PERFORM check
END-PERFORM
CLOSE indexfile
MOVE 0 TO einde
lees.
OPEN INPUT indexfile
MOVE 1 TO id-number
READ indexfile
INVALID KEY
DISPLAY "Invalid key: " id-number
NOT INVALID KEY
DISPLAY id-number SPACE fname SPACE lname SPACE
city SPACE hobby
END-READ
CLOSE indexfile
MOVE 0 TO einde
ACCEPT einde