|
Dan, I have coded like this in the past, the only thing I didn't like about it was the if statement that could get extremely large if the record processing was complex. The other option is to use the leave statement, but I personally don't like to use leave or other type of break out of the loop instructions. Then again, I've been bitten by the 2 reads before, when I needed to change the read statement for some reason and only remembered to change one of the 2 and forgot about the other one. One way I handled this in the past with a complex read statement (setting up variables, etc..) was to actually put the read and supporting statement in a subroutine, and call the subroutine each time so I only had to change the read once, not elegant either. I don't think there is a truly elegant way to do this in RPG, although C has solved the problem with it's syntax: while ( read(somefile, somebuffer) != NULL ) { } which we don't seem to have (yet) in RPG. I flip flop on how I handle this now and then, and am not really happy with any method in RPG right now. Regards, Jim Langston -----Original Message----- From: Dan Bale [mailto:dbale@samsa.com] <sigh> <asbestos suit on> I think I'm gonna regret this, however, Juan, you should know that your original code was close. I tend to respectfully disagree with the "two reads in a loop" camp, as Jim provided in his code. I am definitely in the "one read in a loop" camp. The only changes I would have made to your original code: C KlistB SetLL IN057P2 C DOW Not %EOF(IN057P2) C KlistB ReadE IN057P2 C If %EOF(IN057P2) C Leave C EndIf C ... do your stuff C EndDo would have been to use a DoU %EOF(IN057P2) in place of the DOW, and use If Not %EOF(IN057P2) in place of the If %EOF(IN057P2) & Leave. Here's how I would normally code what I believe you are trying to accomplish: C KlistB SetLL IN057P2 C DOU %EOF(IN057P2) C KlistB ReadE IN057P2 C If Not %EOF(IN057P2) C ... do your stuff C EndIf >If Not %EOF(IN057P2) C EndDo >DOU %EOF(IN057P2) In this case, you do not need to prime your %EOF because you are not testing it until the EndDo, after you've attempted a ReadE (note the DOUntil vs. DOWhile). I *personally* find this much easier to read & maintain than the READ before the loop and at the bottom of the loop technique. Additionally, if you wanted to perform data selection on your read input, you've already got your If statement, i.e.: C If Not %EOF(IN057P2) C and INRcvDate = TodaysDate HTH <keeping the asbestos suit on>
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.