I try to convert this loop to dbeval() but certain records are omitted in the dbeval() routine below.
Static Function _GetBatchTotals()
Local aBT[0], cJVN
Select("MyTable")
Do While !Eof()
cJVN := MyTable->JVN
aBT := {0,0}
Do While cJVN == MyTable->JVN
aBT[1] += Mytable->dr
aBT[2] += Mytable->cr
DBSkip()
Enddo
Enddo
Return(aBT)
Static Function _GetBatchTotals()
Local aBT[0], cJVN
Select("MyTable")
DbEval({|| cJVN := MyTable->JVN, aBT := {0,0}, DC_Dowhile({|| cJVN == MyTable->JVN}, {||aBT[1] += Mytable->dr, aBT[2] += Mytable->cr, dbSkip() })})
Return aBt
dbEval()
Re: dbEval()
dbEval() automatically does a dbSkip() through all records that match your conditions.certain records are omitted in the dbeval() routine below.
If you put a dbSkip() in the code block, you will miss every other record.
The eXpress train is coming - and it has more cars.
Re: dbEval()
Hi Roger
My upper routine that utilises nested do .. while works just fine and that is what I am trying to accomplish using dbeval(). Without the dbskip I get incorrect result
Thanks.
Joe
My upper routine that utilises nested do .. while works just fine and that is what I am trying to accomplish using dbeval(). Without the dbskip I get incorrect result
Thanks.
Joe
Re: dbEval()
I see that you don't have an alias on your dbSkip() function.
Maybe that's the problem.
You may be skipping the wrong work area.
Maybe that's the problem.
You may be skipping the wrong work area.
The eXpress train is coming - and it has more cars.
-
- Posts: 42
- Joined: Mon Dec 23, 2013 2:10 pm
- Contact:
Re: dbEval()
False logic
suppose the table is sorted on the variable JVN
The array aBT contains the last values of the table corresponding to the last value of JVN since aBT is reinitialized with each change of the value of JVN.
to have the same result:
Static Function _GetBatchTotals()
Local aBT[0], cJVN
Select("MyTable")
aBT := {0,0}
Go bott // Last Value JVN
cJVN:=MyTable->JVN
Locate for JVN=cJVN
// OR if indexed
// MyTable->(Dbseek(cJVN))
DbEval({|| aBT[1] += Mytable->dr, aBT[2] += Mytable->cr},,,,,.T.)
Return aBt
suppose the table is sorted on the variable JVN
The array aBT contains the last values of the table corresponding to the last value of JVN since aBT is reinitialized with each change of the value of JVN.
to have the same result:
Static Function _GetBatchTotals()
Local aBT[0], cJVN
Select("MyTable")
aBT := {0,0}
Go bott // Last Value JVN
cJVN:=MyTable->JVN
Locate for JVN=cJVN
// OR if indexed
// MyTable->(Dbseek(cJVN))
DbEval({|| aBT[1] += Mytable->dr, aBT[2] += Mytable->cr},,,,,.T.)
Return aBt