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

Is it possible to...?

Status
Not open for further replies.

Snookless

Technical User
Mar 17, 2003
34
0
0
BR
.......get grand totals from a sub report onto the main report, then how to use those fields in an expression to subtract one from the other.
Thank you all..
Snookless


 
Absolutely you can - depending on your version of Crystal, look up the online help on variable scope - Crystal generally supports three type of variables, local, global and shared. A shared variable can be used throughout the main report AND any subreports. So, in your subreport, create a formula to store your value e.g.;

Shared NumberVar x := 1000;

You should then be able to recover the value in your main report with a formula like so;

Shared NumberVar x;

Where x is the name of your variable, and 1000 is the value being stored in x. It's a little more complex than described here, but you should get the general idea.
 
I apologize for this but is there an easier explanation?
snookless
 
I understand that I need to learn how to use shared variables, so can someone tell me where/how I could learn this. My question is that I need to create a formula that takes the sum of the subreport and adds it to a parameter field that I have. That will then give me a balance. So I if I was create a shared variable what would be x and what would be the 1000 (from previous post). Would x the field name and the 1000 be the sum of the field name?

Thanks
Dianna
 
There are lots of posts here that demonstrate using shared variables, use the Keyword Search tab.

A shared variable is used in a formula, as in:

In the subreport:

whileprintingrecords;
shared numbervar MyNumber := sum({table.field});

Back in the main report after the subreport fires:
whileprintingrecords;
shared numbervar MyNumber;
MyNumber + {?MyParameter}

It's very unusual to add a shared variable to a parameter...

Also, try creating a new post, often times people ignore 5 month old posts that suddenloy became active.

-k
 
Thank you that makes so much more sense than the x=y stuff. It is almost working for me. I can get the shared variable in the subreport to bring up the correct amount (I'm using the currencyvar), but when I add that variable with my parameter (even tried another field that was not a parameter) it is only bringing up the parameter amount.

Thank you again, this has been a huge help!!
 
Okay, I've tried everything I can think of and cannot get it to work. I have taken the sum of a field in my subreport and made it a currencyvar (shared variable). I then go to primary report and create a formula taking the shared variable + a parameter. It will only show the parameter amount in the forumla field. Here is what I have:

Subreport Formula:
whileprintingrecords;
shared currencyvar FeeBal := Sum ({R_RTR_FEEBALS.feebalance})

Primary Report Formula:
whileprintingrecords;
shared currencyvar FeeBal;
FeeBal+{?PendingFees}

If I leave out the "+ {?PendingFees}", the field shows 0.00. It's not recognizing the shared variable at all. Any help would be great!
Thanks
Dianna


 
When you use the WhilePrintingRecords statement in a formula (which is essential for the task you are attempting), the variables are evaluated in the order in which they are encountered by Crystal as the report is printed. So, if you put the Primary report formula in, say, Group Header 1, but put the subreport in Group Footer 1, the shared variable has no value when the formula in the Group Header is calculated. The Primary Report Formula must occur (be located) after the subreport. So the issue probably turns on where in the report you've placed the subreport and where in the report you've placed your Primary Report Formula. Where are these two items in your report?
 
They are both in the details section of the primary report, but the subreport is below the field I am try to create. I tried to put the field below the subreport and that didn't do anything. I really need both fields in the details section of the primary report. Unless I could put the subreport also in the group header and supress the header and also have it in the details. Does that make any sense?

Thanks
Dianna
 
Well, in order for the primary report formula to work, you would need to have multiple detail sections (i.e., a Details section A and Details section B. You can create multiple sections by using the Section Expert. Click on the details section and then click the Insert Button. A Details B will be created below Details A). Place the subreport in Details A and the primary report formula in Details B. If you need Details A and B to appear on the same line, in the Section Expert check the box that says Underlay Following Sections for Details A.

By the way, it is unusual to have a subreport in a details section. I would say that 95% of the time I've seen someone do this, it's because they don't know how to do proper joins in their database. I'm not saying that is your case, but you would be among the 5% I've seen who actually need it. If your report brings back 1000's of records, your performance is going to be really bad. You might consider reviewing how you are collecting your data in the first place.
 
Thanks, I'll try the 2 details section. The reason I have the subreport in the details is because it is like a small table of fees. I basically have the primary report and then a box with the fee information. It is based off of id number and any id can have multiple fees or no fees. Basically I want the fee information(subreport) to look like it is part of the primary report. I have them joined together by id number so that only fees for that 1 id shows up on each report.
 
So, instead of a subreport, why don't you do a left outer join to the fee table on the id number field? Then group your report by the id number field. Whatever you currently have in the details section could go in the group header, and your details would contain the fees. That's pretty much a guess, since I really don't know the design of your report, but the theory sounds right.
 
Thanks, that does make more sense. Now the problem I have is one id may have muliple fees attached to it. Say 1 id has 3 fees, so then 3 reports print out. What I would like to see is a list of those fees on the report. Whether it is 1 fee or 5 fees. Then take a sum of the fees and add it to a parameter field I have. I figured in my sql view (which I was using for the subreport) I could sum the fees and then pull that field into the report.

I just want to say thank you for all your help. Even if I don't use the subreports, it has been a great learning experience. This is a great forum and I am so glad I found it.
 
Well, if you group on the ID field, then all you will want to show in the details section of your report are the fields related to the fees. For illustration purposes, suppose you have three ID's, the first 3 fees, the second with 5 fees, and the third with no fees, with you'll get:

Group Header ID 1
Detail Fee 1
Detail Fee 2
Detail Fee 3
Group Footer ID 1

Group Header ID 2
Detail Fee 1
Detail Fee 2
Detail Fee 3
Detail Fee 4
Detail Fee 5
Group Header ID 2

Group Header ID 3
Detail
Group Footer ID 3

The reason for the single detail record in the last case is that your dataset will show 1 record for ID 3 with Nulls in the fee related fields (due to the Left Outer Join). So, you may want format the detail section to suppress blank sections, so you only get:

Group Header ID 3
Group Footer ID 3

Anyway, your summaries can be done in the group footer.

You can format "fee" fields anyway you want (to appear as a "report"). If you need a "header" section for the details, beyond what is being shown in the group header, Insert a new section in the ID Group Header (it will show as Group Header B) and conditionally suppress it when there are no detail records.

That's kind of the overview, without too many details on how to so things like conditional suppression or inserting new sections. If you have questions on specific issues, please post them and I'm sure someone in the forum will help you out.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top