Lets us suppose I have a file A having below data:
A1.01
A2.02
A4.03
A6.01
And a file B having following data:
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
Its is required to delete the records present in the file A from file B, if it matches the first two letters data of records of second file.
Therefore output should look like:
A5.01 kdkgskhdgss
A5.02 fljsdfjdfjd
A5.03 sdjdhsdhsld
A7.04 jhsdhskdhsd
A7.07 dsjdhslkhds
I have file A having 400 records and file B having half million records. I ran a COBOL program but it ran for too long.
The cobol program logic is as follows:
Here I have taken the half million records contating file as A.
And the file containing 400 records as file 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.
[Sample File-control, file section and required working-storage added for clarity.
Follow the bouncing ball for the other files involved. Filenames referenced are for my testing. sample only for brevity's sake]
No need for any flags, just file-statuses. Certainly no need for evil perform-throughs which create layout-dependent code.
This assumes your data is sorted as you have indicated. If it isn't then the approach would be different - read the exclusions file field in question (the two characters) into a working-storage table, sort and search the table for a match against each main file record read.