让我们假设我有一个文件 A 具有以下数据:
A1.01
A2.02
A4.03
A6.01
文件 B 具有以下数据:
A2.02 xyshahaslsl
A2.02 dkjhsldhsds
A2.02 ewewhrewjws
A4.03 wejwejwrewl
A4.03 wejedededee
A5.01 kdkgskhdgss
A5.02 fljsdfjdfjd
A5.03 sdjdhsdhsld
A7.04 jhsdhskdhsd
A7.07 dsjdhslkhds
如果它与第二个文件的记录的前两个字母数据匹配,则需要从文件B中删除文件A中存在的记录。
因此输出应如下所示:
A5.01 kdkgskhdgss
A5.02 fljsdfjdfjd
A5.03 sdjdhsdhsld
A7.04 jhsdhskdhsd
A7.07 dsjdhslkhds
我的文件 A 有 400 条记录,文件 B 有 50 万条记录。我运行了一个 COBOL 程序,但运行时间过长。
cobol 程序逻辑如下:
这里我将包含 50 万条记录的文件作为 A。
将包含 400 条记录的文件作为文件 B。
WORKING-STORAGE SECTION.
01 WS-RECORDS-WRITTEN PIC 9(8) VALUE ZEROES.
01 WS-RECORDS-DELETED PIC 9(8) VALUE ZEROES.
01 WS-INSERT-FILE-STATUS PIC X(2).
01 WS-EOFA PIC A(1) VALUE 'N'.
01 WS-EOFB PIC A(1) VALUE 'N'.
01 WS-FLAG-FOUND PIC A(1) VALUE 'N'.
PROCEDURE DIVISION.
MAIN-PARA.
OPEN INPUT IFILEA
OPEN OUTPUT OFILE
PERFORM PARA0 THRU PARA0-EXIT UNTIL WS-EOFA = "Y"
CLOSE IFILEA
CLOSE OFILE
STOP RUN.
EXIT.
PARA0.
READ IFILEA
AT END MOVE "Y" TO WS-EOFA
END-READ
IF WS-EOFA = "N"
OPEN INPUT IFILEB
MOVE "N" TO WS-EOFB
MOVE "N" TO WS-FLAG-FOUND
PERFORM PARA1 THRU PARA1-EXIT UNTIL WS-EOFB = "Y"
OR WS-FLAG-FOUND = "Y"
IF WS-FLAG-FOUND = "N"
WRITE F2RECORD FROM F0RECORD
END-IF
CLOSE IFILEB
END-IF.
PARA0-EXIT.
EXIT.
PARA1.
READ IFILEB
AT END MOVE "Y" TO WS-EOFB
END-READ
IF OSS024S-TRACKING-ID = OSS024V-REC
* SKIP THE RECORD
MOVE "Y" TO WS-FLAG-FOUND
END-IF.
PARA1-EXIT.
EXIT.