The problem were are solving here:
You have 2 files, one has records (lines) with “key” values in the first word, the second has records (lines) “key” values in the second word. (A Word here is defined as a string delimited by blanks – similar to the definition in Rexx – See Rexx Reference)
For all of the key entries in file1 you want to know if key entries exist in file2. If the key entry does not exist the record in file2 is written to the output file.
The solution in Rexx below works as follows:
Build a simple hash table of key entries in file1. For each record in file2, check if the key value has an entry in the hash table. If not, write the record to the outfile file.
BTW in Rexx programs for files that are not excessively large, I have the habit of reading them fully into a stem variable before processing. Similarly I use a stem variable to capture the output data, and write that in one go after processing is complete. Not sure if that is a good habit, but it makes programming easy.
/* Rexx */ trace off /* Fill InpRec1. and InpRec2. */ Call ReadInput /* Fill filter. */ Drop filter.Do N = 1 To InpRec1.0 entryname = Word(InpRec1.N,1) filter.entryname = 1 End /* Do */ /* Compare old file with new and write output */ Drop OutRec1.OutRec1.0 = 0 Do N = 1 To InpRec2.0 entryname = Word(InpRec2.N,2) If filter.entryname = 1 Then Do NOP /* This entry exists in both, that's ok */ Say 'To be skipped : ' entryname End Else Do /* Write this line, this entry has to be processed */ help = OutRec1.0 + 1 OutRec1.help = InpRec2.N OutRec1.0 = help End End /* Do */ Call WriteOutput Exit /*******************************************************************/ /* Routines ********************************************************/ /*******************************************************************/ /*******************************************************************/ ReadInput: Address Tso 'EXECIO * DISKR FILTER (Stem InpRec1. Finis' If RC <> 0 Then Do Say 'Error reading input file FILTER, Rc = ' RC Exit 69 End 'EXECIO * DISKR INPLIST (Stem InpRec2. Finis' If RC <> 0 Then Do Say 'Error reading input file INPLIST, Rc = ' RC Exit 69 End Return /* ReadInput */ /*******************************************************************/ WriteOutput: Address Tso 'EXECIO * DISKW OUTLIST (Stem OutRec1. Finis' If RC <> 0 Then Do Say 'Error writing output file OUTLIST, Rc = ' RC Exit 69 End Return /* WriteOutput */