Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Summarizing Shared Variable

Status
Not open for further replies.

michbell

Technical User
Aug 12, 2004
25
US
I`m pretty new to Crystal, and I can`t figure out how to summarize formula that is calculated from the subreport. Here`s the situation:

In the subreport I have the following —

//@subformula
//stores the grand total of the
//{@cost} field
//in a currency variable called `myTotal`

whileprintingrecords;
shared currencyvar myTotal := sum({@cost})


Then in the main report —

//@MainFormula
//Returns the value that was stored
//in the shared currency variable called
//myTotal in the subreport

Whileprintingrecords;
shared CurrencyVar myTotal;
myTotal


Then I placed this formula {@stcost}in the details section:

{@MainFormula}*{lbs_scrapped}/{net_per_1000}


Everything works out fine with this setup, but then I try to create the following formula:

Sum({@stcost}, {date}, “daily”) ------ my report is grouped by days


But then I get the error – this field cannot be summarized. What am I doing wrong???? Thanks in advance.
 
Where the subreport is in the main report is critical, as is version of your software and the database/connectivity used as you may not even need a subreport (they're slow).

A shared variable can't be summed, you may want to read up on the Crystal 3 pass system.

To sum a shared variable passed from a subreport, here's an example:

Report Header:
//Reset the shared variable in a formula to 0
Whileprintingrecords;
shared CurrencyVar myTotal:=0;

Group Header:

Subreport in the Group Header:
//Return the shared variable value from the subreport
Whileprintingrecords;
shared CurrencyVar myTotal:=myTotal+sum({table.field})

Report Footer:
//Display the summed value
Whileprintingrecords;
shared CurrencyVar myTotal

The point is to add the sums into another shared variable.

-k
 
I'm using CR 9 and pulling the info from an Informix Online Server (UNIX).

The formulas you gave for the RH/RF, is that something you think would work in my case, or is that just an generic example?

I read up a little on the pass system, but I just don't know how to apply it to fix my problem.

Thanks again!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top