Page 1 of 1

Using relationship

Posted: Thu Jul 04, 2013 1:29 pm
by NickSteel
If I have:

Select 0
Use BBB alias BBB
Index on Field01 to BBB

Select 0
Use AAA alias AAA
Index on Field01 to AAA

Set Relation to AAA->Field01 Into BBB
Go Top
Do While !Eof()
Total := Total + if(BBB->Date01 = AAA->Date01 .AND. BBB->Field02>0 ,1,0)
Skip
Enddo

What is the easiest way to check if I have a BBB for each AAA during the Do While loop without seeking? Can I use FOUND() within the line? If so, how?

Re: Using relationship

Posted: Thu Jul 04, 2013 2:35 pm
by dhaine_adp
Hi Nick,

Try to adopt the code below into your source code, maybe it can help.

Code: Select all

** Use ORDSCOPE()


function Main()

LOCAL nTotal := 0

PRIVATE cPrimeKey := ""   // must be declared as private

Select 0
Use BBB alias BBB
Index on Field01 to BBB

Select 0
Use AAA alias AAA
Index on Field01 to AAA

dbselectarea( "BBB" )
dbgotop()
while .not. eof()
   cPrimeKey := BBB->Field01

    dbselectarea( "AAA" )
    ORDSCOPE( 0, "&cPrimeKey" )
    ORDSCOPE( 1, "&cPrimeKey" )
    dbgotop()  // go top is required here
    while .not. eof()
       nTotal += if(BBB->Date01 = AAA->Date01 .AND. BBB->Field02>0 ,1,0)
       dbskip()
    end

    dbselectarea( "BBB" )
    BBB->dbskip()
end


Using relationship

Posted: Thu Jul 04, 2013 2:40 pm
by Pablo César
Total := Total + if(BBB->Date01 = AAA->Date01 .AND. BBB->Field02>0 ,1,0)
According this, I think what you are needing is to know how many records are with same date in both files and in BBB->Field02 must be different than zero.

Remembering all command in dBase, I should try this:

Count to Total for (BBB->Date01 = AAA->Date01 .AND. BBB->Field02>0)

I did not teste, so I not sure if gonna works but try and in other cases you can use Count command without any filter (filters normally become having/slow process) and also do not need index files too. But take in count that you need to process up the dbfs files.

IMO, if this information is frequently used, you need to be recorded at same time you are inputing data.

Re: Using relationship

Posted: Thu Jul 04, 2013 6:25 pm
by esgici
NickSteel wrote:If I have:

Select 0
Use BBB alias BBB
Index on Field01 to BBB

Select 0
Use AAA alias AAA
Index on Field01 to AAA

Set Relation to AAA->Field01 Into BBB
Go Top
Do While !Eof()
Total := Total + if(BBB->Date01 = AAA->Date01 .AND. BBB->Field02>0 ,1,0)
Skip
Enddo

What is the easiest way to check if I have a BBB for each AAA during the Do While loop without seeking? Can I use FOUND() within the line? If so, how?
You don't need FOUND(), try this loop :

Code: Select all

Do While !Eof()
     Total := 0
     WHILE BBB->Date01 = AAA->Date01
           Total += IF( BBB->Field02>0  ,1,0)
           BBB->(DBSKIP())
    ENDDO 
    ? "Count of", AAA->Field01, Total
    Skip
Enddo
Note : This is a Harbour issue, not HMG.

Re: Using relationship

Posted: Sat Jul 06, 2013 10:08 am
by esgici
Hi Nick
esgici wrote:... try this loop :
What about result ?

If unsuccessful, if you will post a little data we can make more search.

Re: Using relationship

Posted: Sat Jul 06, 2013 2:29 pm
by NickSteel
I finally used (after trial and error):

tot1=tot1+if( ! BBB->(EOF()),1,0)