|
These are both very nice, but they won't work unless the last record in both files is a matching
record. So you have to add some complexity to prevent an infinite loop in all but one circumstance.
/free
read file1;
read file2;
dow (not %eof(file1) or not %eof(file2));
select;
when old.key = new.key;
update file1; //matched records logic...
read file1;
read file2;
when (old.key < new.key and not %eof(file1))
or %eof(file2);
delete file1; // old file record no longer needed.
read file1;
other; // (old.key > new.key and not %eof(file2))
// or %eof(file1) = New record!
write file1; // using file2 fields
read file2;
endsl;
enddo;
*inlr = *on;
/end-free
You don't have to deal with that for MR logic. Now try making it work for three files. The
complexity increases exponentially. But not with MR logic. With MR logic you have a predefined
behavior that works the same whether you are matching records from two files or three or more. If you
are looking for a different behavior, then you will have to code it yourself. Do you really want to
code it if you don't have to?
BTW, this really won't give you the same progression of records as MR logic. If there are record
formats involved that do not include match fields this won't work, but even if all record formats have
match fields you could get something different. MR logic will select one record at a time for
processing, and the match fields do not have to be primary key fields. This means that each match can
be found on multiple records of both files. Reading both files each time there is a match can result
in a much different record progression than what you get with MR logic.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.