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?
Using relationship
Moderator: Rathinagiri
- dhaine_adp
- Posts: 457
- Joined: Wed Aug 06, 2008 12:22 pm
- Location: Manila, Philippines
Re: Using relationship
Hi Nick,
Try to adopt the code below into your source code, maybe it can help.
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
Danny
Manila, Philippines
- Pablo César
- Posts: 4059
- Joined: Wed Sep 08, 2010 1:18 pm
- Location: Curitiba - Brasil
Using relationship
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.Total := Total + if(BBB->Date01 = AAA->Date01 .AND. BBB->Field02>0 ,1,0)
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
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
- esgici
- Posts: 4543
- Joined: Wed Jul 30, 2008 9:17 pm
- DBs Used: DBF
- Location: iskenderun / Turkiye
- Contact:
Re: Using relationship
You don't need FOUND(), try this loop :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?
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
Viva INTERNATIONAL HMG
- esgici
- Posts: 4543
- Joined: Wed Jul 30, 2008 9:17 pm
- DBs Used: DBF
- Location: iskenderun / Turkiye
- Contact:
Re: Using relationship
Hi Nick
If unsuccessful, if you will post a little data we can make more search.
What about result ?esgici wrote:... try this loop :
If unsuccessful, if you will post a little data we can make more search.
Viva INTERNATIONAL HMG
Re: Using relationship
I finally used (after trial and error):
tot1=tot1+if( ! BBB->(EOF()),1,0)
tot1=tot1+if( ! BBB->(EOF()),1,0)