× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



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.

-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Chris Pando
Sent: Tuesday, December 18, 2007 7:55 PM
To: RPG programming on the AS400 / iSeries
Subject: Re: Matching Records - End Product

On Dec 18, 2007 4:50 PM, Mike Krebs <majkrebs@xxxxxxxxx> wrote:
I wrote my own matching logic program to integrate a batch update to a live file. I did it in free
form. In 20 years of programming in this environment (system 36/38/as400) I saw one or two MR programs
(and that might have been in school!) Also, it just seemed easier to me.


I am not at work, so I don't have the exact code available, but the logic is not very hard and looks
something like this. Obviously without the exact code, I improvised and use some psuedo code. But, the
guts are pretty straight forward.


ffile1 prefix(old)
ffile2 prefix(new)


/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;
delete file1; // old file record no longer needed.
read file1;
other; // old.key > new.key = New record!
write file1; // using file2 fields
read file2;
endsl;
enddo;
*inlr = *on;


/end-free

Indeed. I have a generic matching record program (I use it for
regression testing) and the code is very similar:

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * *
* * * Mainline * * *
* * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/free
init();
read1();
read2();
DoW (Not %Eof(input1) Or Not %Eof(input2));
testVar = compKey();
Select;
When (testVar = L_LESS);
error1();
read1();
When (testVar = R_LESS);
error2();
read2();
When (testVar = EQUAL);
If (compDta() <> EQUAL);
error3();
EndIf;
read1();
read2();
EndSl;
EndDo;
hndlNoErr();

Return;
/end-free

http://www.brilligware.com/cp1000r.html


Chris
--
chris@xxxxxxxxx
www.brilligware.com

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

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.