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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using a shared variable froma sub report multiple times 1

Status
Not open for further replies.

unclejimbob

Technical User
Oct 12, 2005
128
AU
Hi all, I've had a look around the posts but can't find anyone with a similar issue.

Here is the problem :- I have a main report that calls a sub report and the sub report returns the number of enquiries for a particular product. Don't ask me why I am using a sub report its not really relevant to explain here :)

The sub report formula looks like this:

WhilePrintingRecords;
Shared NumberVar myEnquiries;
myEnquiries := myEnquiries + Count ({Command.EVENTUID})

I have created a formula in the main report thus:

WhilePrintingRecords;
Shared NumberVar myEnquiries;
myEnquiries

which I use to count the number of enquiries and which displays the returned information in a group footer and I reset the enquiry count to zero using another formula held within a suppressed group header thus:

WhilePrintingRecords;
Shared NumberVar myEnquiries := 0;

So far so good.

The problem occurs because I want to use this information in other group footers in the report, for example I want the number of enquiries by the 'category' of the product and then a total of all enquiries for the entire report.

I have experimented with using a number of other sub reports but it seems overkill to create one sub report for each grouping - so my question is 'Is there a way I can use the same shared variable passed back from the sub report within multiple groups ?'

thanks all
 
Perhaps you could post technical information, such as what are the groups, and where is the subreport located, and what are you intending to display at what level?

Your post is a broad overview, nothing particular other than naming one group and alluding that there are others, somewhere...

A subreport doesn't live within multiplke groups, it exists within one, and that is the data it will return, this assumes that you have it linked by the group field value.

Try posting example data, and expected output, you'll receive appropriately tailored responses.

-k
 
Your post is a broad overview, nothing particular other than naming one group and alluding that there are others, somewhere..."

Yes, the post was a deliberately broad overview because I wanted to receive a reply along similar lines.

I thought the question pretty clear myself. Is there the ability to use the information retrieved from a sub report via a shared variable in more than one report group ? Either Crystal has this ability or it hasn't, or there is some other alternative.

"A subreport doesn't live within multiplke groups, it exists within one, and that is the data it will return, this assumes that you have it linked by the group field value."

Er, I don't want to put a sub report in multiple groups, I just want the shared data that it returns to be able to be summarized in more than one group.

"Try posting example data, and expected output, you'll receive appropriately tailored responses."

I'm not sure that a tailored response is what I need but here goes :)

My main report returns the number of enquries for each product for a list of products.

Product 1 has 200 enquiries, Product 2 has 300 enquiries.

Product 1
200

Product 2
300

products are organized into categories so this is what is required as the final output...

Category 1
Product 1
200
Product 2
300
500 (total enquiries for Category 1)
Category 2
Product 3
100
Product 4
50
150 (total enquiries for Category 2)

So each category sums up the number of enquiries for each product.

Now the main report has two report footers, one grouped by the product itself which calls a sub report that returns a figure (namely the number of enquiries for the product) thus:

Product 1 200

This value is then returned to the main report in the same manner as every one else on the planet uses - via a shared variable named myEnquiries.

So at this point I have this sort of output:

Category 1
Product 1
200
Product 2
300

Category 2
Product 3
100
Product 4
50

Now, all I want to do is to be able to use the myEnquiries shared variable to add 200 + 300 for the products under Category 1 and 100 + 50 for the products under Category 2 to give me totals for the Category group.

...and if I wish to add yet another group that is higher than the Category group then it would be nice once again to be able to sum the same variable to get more grouped summaries.

As stated before I have looked at alternatives such as creating subreports for each and every group that I create (and in fact this is my current 'solution' ) but crikey what a hassle !!!

thanks
 
I'm not sure where your subreport is located. Let's say it is in your product group in GH#2b, and that you have your reset shared variable formula in GH#2a. Let's say your display formula is in GF#2.

First, I think your subreport shared variable formula should just be:

WhilePrintingRecords;
Shared NumberVar myEnquiries;
myEnquiries := Count ({Command.EVENTUID});

Then change your display formula in GF#2 to:

//{@accum}:
WhilePrintingRecords;
Shared NumberVar myEnquiries;
numbervar catmyEnq := catmyEnq + myEnquiries;

In the GH#1 header, place this formula:

whileprintingrecords;
numbervar catmyEnq;
if not inrepeatedgroupheader then
catmyEnq := 0;

In the GH#1 footer, use the following to display the group total:
whileprintingrecords;
numbervar catmyEnq;

If you need a report level total, you would add another variable to the {@accum} formula, using another variable name like:

numbervar grtot := grtot + myEnquiries;

Then use a display formula in the report footer:

whileprintingrecords;
numbervar grtot;

-LB
 
I'm not sure where your subreport is located. Let's say it is in your product group in GH#2b, and that you have your reset shared variable formula in GH#2a. Let's say your display formula is in GF#2."
Yeah, sorry, this bit "Now the main report has two report footers, one grouped by the product itself which calls a sub report that returns a figure (namely the number of enquiries for the product) thus:" is misleading, I meant that I have two group footers one for products (in which the sub report lives) and one higher up that groups products by category.

"First, I think your subreport shared variable formula should just be:

WhilePrintingRecords;
Shared NumberVar myEnquiries;
myEnquiries := Count ({Command.EVENTUID});
"
Yeah, spot, on, this is what I had originally but I was trying all sorts of weird ways to get the sub report to do the work (which was naughty of me!)

"//{@accum}:
WhilePrintingRecords;
Shared NumberVar myEnquiries;
numbervar catmyEnq := catmyEnq + myEnquiries;

In the GH#1 header, place this formula:

whileprintingrecords;
numbervar catmyEnq;
if not inrepeatedgroupheader then
catmyEnq := 0;"

Yeah, brilliant, this is just what I was after. The example I was using had the shared var in the sub report and the main report as the same name and I thought that
this was a constraint imposed by Crystal, i.e. I'd have to send back multiple copies of the information in different shared vars in order to be able to create the appropriate formulas in the main report. Your example shows that this is not the case and that the shared var can be used in more than one group. You just saved me several hours unnecessary work for which I am grateful.
 
Okay, but you understand that the shared variable is referenced under the same name in the main report in {@accum}--it is just that it is being accumulated in one or two different variables (catmyEnq and/or grtot) in the main report.

-LB
 
Okay, but you understand..."

Sorry, been away from this for a while - hence the lack of response from me.

Yes, I fully understand this, from what you provided I got the report up and running after another 15 minutes work - just a lot of cutting and pasting because of the number of values I was returning from the sub report. Another 15 minutes checking the figures and formatting and I'm done.

They all summarize nicely and on that particular day I was Mr Popular :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top