David, You're correct that the remove is faster, and it is because it maintains an internal pointer to the next item, as opposed to positioning to it for each reference.
And I'm pretty sure that you can make it run even faster with: LINE.KEYS = RAISE(HEADER.REC<200>) As a matter of preference, I would set D1 to 999 or some other numeric value rather than a null, only because Universe/Unidata is typeless, and I would be afraid that the null, (""), might be treated as a zero; but that's just personal fear and preference not based on a horror story. On 2/11/2013 8:30 AM, Dave Laansma wrote: > I would HOPE that it evaluates it each time since the size of <array> could > change within the loop. > > Personally if the size of <array> is relatively small, DCOUNT is alright. > However I've found REMOVE to be EXTREMELY faster and therefore use it > whenever possible, even on small <arrays>. > > For example, we have two files, a 'header' and 'detail' file. The keys to the > 'detail' file are stored in attribute <200> of the header file. So I'll pull > the keys out of the header record, such: > > LINE.KEYS = HEADER.REC<200> > D1 = "" > LOOP UNTIL D1 = 0 > REMOVE LINE.KEY FROM LINE.KEYS SETTING D1 > <loop statements> > REPEAT > > As opposed to: > > FOR V1 = 1 TO DCOUNT(HEADER.REC<200>,@VM) > LINE.KEY = HEADER.REC<200,V1> > <loop statements> > NEXT V1 > > Based on historical dialogs on this subject on this forum, I have seen an > improvement in overall performance. > > Sincerely, > David Laansma > Hubbard Supply Co. > Direct: 810-342-7143 > Office: 810-234-8681 > Fax: 810-234-6142 > www.hubbardsupply.com > "Delivering Products, Services and Innovative Solutions" > > -----Original Message----- > From: u2-users-boun...@listserver.u2ug.org > [mailto:u2-users-boun...@listserver.u2ug.org] On Behalf Of Jeffrey Butera > Sent: Monday, February 11, 2013 7:55 AM > To: firstname.lastname@example.org > Subject: Re: [U2] : Evaluating DCOUNT > > On 02/11/2013 12:14 AM, Peter Cheney wrote: >> Hi Everyone, >> >> Does a DCOUNT get evaluated again for each iteration of a loop? >> Or is UniVerse these days intelligent enough to keep track of what's going >> on? >> >> e.g. >> >> for i = 1 to dcount(array,@fm) >> *commands here >> next i >> >> versus >> >> totalattributes = dcount(array,@fm) >> for i = 1 to totalattributes >> *commands here >> next i >> >> Apart from readability and perhaps easier debugging is there an actual >> internal difference? >> I know it was an issue on older pick releases but I cannot remember if it >> ever affected UV? > > Not sure about universe, but unidata defintely checks the DCOUNT for each > iteration. This produces 4 (not 2): > > > CT=0 > X=45:@VM:58 > FOR I=1 TO DCOUNT(X,@VM) > CT+=1 > IF I<=2 THEN > X<1,-1> = 99 > END > NEXT I > CRT CT > > _______________________________________________ U2-Users mailing list U2-Users@listserver.u2ug.org http://listserver.u2ug.org/mailman/listinfo/u2-users