views:

210

answers:

1

Is it possible to programmatically iterate through a table within a formula in crystal reports?

E.G. If I have a master table and a detail table can I iterate through the detail table e.g.

( psuedo code )

local numberVar Total := 0

While not EOF()

IF Type = "+"
    Total = Total + Quantity
ELSE IF Type = "-"
    Total = Total - Quantity
ENDIF

<Next Record>

End While

+2  A: 

It is possible to use loops in a formula field to get the data that you need, but I have only really used them in complex string manipulation. If you really need to do this then you may be able to look into using subreports, but you'd need to put the subreport in the details section which is not really recommended because it is essentially like running a new report for each record that is pulled.

It sounds like what you are really looking for is a running total field. If you join the master and details tables together the report will pull all of the rows for both tables. Then you can group by "Type" and create a running total field that sums the "Quantity" field for each row and resets on the change of the group. I think it is a little different way of thinking than traditional programming. Hope this helps.

Dusty