I wrote this little subroutine that will accomplish this easily.  You
can either pass in just the file name or the file name with a much of
selection criteria:

  SUBROUTINE HUB.COUNT.FILE (FILENAME,RCNT)

  CMD     = 'COUNT'
  CMD<-1> = FILENAME
  SWAP @AM WITH " " IN CMD

  CALL SB.DISP(9,CMD)

  EXECUTE CMD CAPTURING MSG RETURNING ERR

  RCNT = ERR<2,2>

  IF RCNT = "" THEN
    RCNT = ERR<1,2>
  END

9999

  RETURN

  END

David Laansma
IT Manager
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: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Dave Laansma
Sent: Friday, November 14, 2008 7:57 AM
To: [email protected]
Subject: RE: [U2] SELECT-READNEXT That's odd

The 'COUNT' command is also very good at establishing if and how many
records match a certain criteria without utilizing a select list.

David Laansma
IT Manager
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: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Mecki
Foerthmann
Sent: Friday, November 14, 2008 3:23 AM
To: [email protected]
Subject: Re: [U2] SELECT-READNEXT That's odd

I would actually have expected that behaviour.
What is this piece of code actually try to achieve?
Is READNEXT only used to test if the SELECT statement returned any
items?
In that case the CAPTURING clause with the EXECUTE statement would be a 
better tool to test that.
Or you could execute CLEARSELECT at the bottom of the loop.
Executing a SELECT with an active select list present (especially in a 
loop) can cause all sorts of problems and depending on flavour strange 
results.
Just because it can probably be done this way doesn't mean it is a good 
idea to do it that way.

Jef Lee wrote:
> One of our programmers wrote this snippet:
>
>       FOR YY=1 TO DCOUNT(WORK.ITEM.REC<17>,VM)
>          LISTNUMBER=''
>          SQLCOMMAND=''
>          UNISTATEMENT='SELECT BPM.WORKITEMS WITH
A1="':WORK.ITEM.REC<1>:'" AND
> WITH A2="':WORK.ITEM.REC<2>:'" AND WITH A17="':WORK.ITEM.REC<17,YY>:'"
AND
> WITH A24#"C" AND WITH A24#"R" AND WITH A24#"F"'
>          *MY.REC<1>=UNISTATEMENT
>          CALL SR.EXECUTESQL(LISTNUMBER,UNISTATEMENT,SQLCOMMAND)
>          READNEXT DEPENDANT.ID ELSE
>             * NO ACTIVE ITEMS LEFT I NEED TO UPDATE THE STATUS OF THE
> DEPENDANT TASK
>             CALL
> SR.READSQL('BPM.WORKITEMS',DEP.TASK.REC,WORK.ITEM.REC<17,YY>,'')
>             DEP.TASK.REC<24>='A'
>             DEP.TASK.REC<8>=DATE()
>             DEP.TASK.REC<9>=TIME()
>             CALL
> SR.WRITESQL('BPM.WORKITEMS',DEP.TASK.REC,WORK.ITEM.REC<17,YY>)
>          END
>       NEXT YY
>
> The FOR loop has 2 values to iterate, so it does 2 loops. The function
> SR.EXECUTESQL()does the SELECT call.
> Loop 1 returns 2 keys found.
> Loop 2 returns 0 keys found.
> What's odd is that the select list is empty on loop iteration 2 and
the
> READNEXT is populated the ID with the second key from the first
iteration.
>
> I looked in the help PDFs and all I found was a reference to a
corrected error
> relating to memory not being released if the READNEXT did not exhaust
the
> SELECT list.
>
> Any thoughts?
>
> We have since changed our strategy to check the count returned
instead. But it
> would be nice to know that others have encountered this as well.
>
> Jeffrey Lee
> Senior Analyst/Programmer
>
> IT Vision Australia Pty Ltd (ABN: 34 309 336 904)
> PO Box 881, Canning Bridge WA 6153
> Level 3, Kirin Centre, 15 Ogilvie Road, Applecross, WA, 6153
> P:  (08) 9315 7000    F: (08) 9315 7088
> W: http://www.itvision.com.au
> ___________________________________________________________
>
> NOTICE : This e-mail and any attachments are intended for the
addressee(s)
> only and may
> contain confidential or privileged material. Any unauthorised review,
use,
> alteration,
> disclosure or distribution of this e-mail (including any attachments)
by an
> unintended recipient
> is prohibited. If you are not the intended recipient please contact
the sender
> as soon as
> possible by return e-mail and then delete both messages.
> ___________________________________________________________
> -------
> u2-users mailing list
> [email protected]
> To unsubscribe please visit http://listserver.u2ug.org/
-------
u2-users mailing list
[email protected]
To unsubscribe please visit http://listserver.u2ug.org/
-------
u2-users mailing list
[email protected]
To unsubscribe please visit http://listserver.u2ug.org/
-------
u2-users mailing list
[email protected]
To unsubscribe please visit http://listserver.u2ug.org/

Reply via email to