|
On Fri, 2005-08-19 at 10:59 -0700, Joel Fritz wrote: > Hmm...It's a religious question. I was brought up in the Brotherhood of > the Priming Read. At the risk of being branded a heretic for even > considering the dread dou: > > setll myfile; > > dou %eof(myfile); > read(myfile); > > if NOT %eof(myfile); > do_stuff(); > endif; > > enddo; The DOU-ers always seem to forget that there are two checks for eof and an extra branch when using DOU. Not a huge deal, but it does add complexity to the code. It occurs to me that if the read opcode would simply return 'true' or 'false' we wouldn't have to have these boring arguments about which loop to use. I don't think it could be much simpler than: /free dow read(myfile); // process the record enddo; /end-free Until such syntactic sugar is introduced into RPG to reduce our burden of choosing an appropriate looping construct, I've devised the 'duzy way' (tm) of file reading thusly: h dftactgrp(*no) h option(*srcstmt:*nodebugio) fexample if e k disk d read_example pr n /free dow read_example(); dsply ('got a record'); enddo; *inlr = '1'; /end-free * * read a record from the example file * return true if end of file is off * return false if a end of file is on p read_example b d read_example pi n d result s n inz('0') /free read example; if not %eof(example); result = '1'; endif; return result; /end-free p e A bit of extra code to combine the reading of the record with the returning of the eof status, and Bob's your uncle. Perhaps one day the RPG gods will look kindly on us and introduce a '%read' bif that will return the EOF status. It would be really great if it could accept a variable that refers to any one of the compiled in files as well. YMMV. Regards, Rich
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.