我希望了解如何读取连续的输入文件并将其作为索引输出到另一个文件。这是我尝试过的代码,虽然我认为它没有正常工作。
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT OLD-INVENT
ASSIGN TO "C:\INVENT5.TXT"
ORGANIZATION IS LINE SEQUENTIAL.
SELECT NEW-INVENT
ASSIGN TO "C:\INVENT6.TXT"
ACCESS MODE IS SEQUENTIAL
ORGANIZATION IS INDEXED
RECORD KEY IS PART-NUMBER1.
DATA DIVISION.
FILE SECTION.
FD OLD-INVENT.
01 OLD-INVENT-IN.
05 PART-NUMBER PIC 9(5).
05 PART-NAME PIC X(20).
05 QUANTITY-ON-HAND PIC 9(3).
05 UNIT-PRICE PIC 9(4)V99.
05 RE-ORDER-POINT PIC 9(3).
05 SUPPLIER-ID PIC X(2).
FD NEW-INVENT.
01 NEW-INVENT-OUT.
05 PART-NUMBER1 PIC 9(5).
05 PART-NAME PIC X(20).
05 QUANTITY-ON-HAND PIC 9(3).
05 UNIT-PRICE PIC 9(4)V99.
05 RE-ORDER-POINT PIC 9(3).
05 SUPPLIER-ID PIC X(2).
WORKING-STORAGE SECTION.
01 END-OF-FILE PIC X(5) VALUE "FALSE".
PROCEDURE DIVISION.
REBUILD-RTN.
OPEN INPUT OLD-INVENT.
OPEN OUTPUT NEW-INVENT.
READ OLD-INVENT
AT END SET END-OF-FILE TO "TRUE"
END-READ.
PERFORM UNTIL END-OF-FILE = "TRUE"
WRITE NEW-INVENT-OUT FROM OLD-INVENT-IN
INVALID KEY DISPLAY "NO RECORD"
END-WRITE
READ OLD-INVENT
AT END SET END-OF-FILE TO "TRUE"
END-READ
END-PERFORM.
CLOSE NEW-INVENT, OLD-INVENT.
STOP RUN.
运行时我得到一堆无效密钥。这是我正在阅读的文件
11111R100widgets small 100040090100CT
11112S150widgets medium 200040090100CT
11113widgets large 300040090100CT
11114widgets brass 400040090100CT
11115widgets bronze 500040090100CT
11116widgets copper 600040090100CT
11118widgets steel 700040090100CT
11121widgets white 800040090100CT
11131widgets silver 900040090100CT
11141widgets plastic 010040090100CT
21111centres small 100040050100BW
21112centres medium 200040050100BW
21113centres large 300040050100BW
21114centres brass 400040050100BW
21115centres bronze 500040050100BW
21116centres copper 600040050100BW
21118R100centres steel 700040050100BW
21121centres white 800040050100BW
21131centres silver 900040050100BW
21141centres plastic 010040050100BW
31111centres small 100040050100HD
31112centres medium 200040050100HD
31113centres large 300040050100HD
31114centres brass 400040050100WP