Using relationship

Moderator: Rathinagiri

Post Reply
NickSteel
Posts: 67
Joined: Mon May 27, 2013 10:44 pm

Using relationship

Post 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?
User avatar
dhaine_adp
Posts: 457
Joined: Wed Aug 06, 2008 12:22 pm
Location: Manila, Philippines

Re: Using relationship

Post 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

Last edited by dhaine_adp on Thu Jul 04, 2013 2:50 pm, edited 1 time in total.
Regards,

Danny
Manila, Philippines
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Using relationship

Post 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.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: Using relationship

Post 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.
Viva INTERNATIONAL HMG :D
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: Using relationship

Post 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.
Viva INTERNATIONAL HMG :D
NickSteel
Posts: 67
Joined: Mon May 27, 2013 10:44 pm

Re: Using relationship

Post by NickSteel »

I finally used (after trial and error):

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