dbEval()

This forum is for eXpress++ general support.
Post Reply
Message
Author
User avatar
unixkd
Posts: 565
Joined: Thu Feb 11, 2010 1:39 pm

dbEval()

#1 Post by unixkd »

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

User avatar
rdonnay
Site Admin
Posts: 4722
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: dbEval()

#2 Post by rdonnay »

certain records are omitted in the dbeval() routine below.
dbEval() automatically does a dbSkip() through all records that match your conditions.
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.

User avatar
unixkd
Posts: 565
Joined: Thu Feb 11, 2010 1:39 pm

Re: dbEval()

#3 Post by unixkd »

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

User avatar
rdonnay
Site Admin
Posts: 4722
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: dbEval()

#4 Post by rdonnay »

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.
The eXpress train is coming - and it has more cars.

messaoudlazhar
Posts: 42
Joined: Mon Dec 23, 2013 2:10 pm
Contact:

Re: dbEval()

#5 Post by messaoudlazhar »

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

Post Reply