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

Shared Variable Question

Status
Not open for further replies.

baycolor

MIS
Mar 23, 2005
148
US
Hi,

I'm using CRV11.

I have a main report with three output fields:
BuName Wave1 Wave2

Main report layout:
RH
PH
D - BuName Wave1 Wave2
Rfa - For a subreport
PF

I have a subreprot with two fields on it:
BuName InvCnt

Subreport layout (groups on BuName):
RH Supressed
GH1 - Surpressed
D - Surpresssed
GF1 BuName InvCnt
RF Surpressed

The main report returns 5 rows for 5 distinct BuNames. The subreport returns 5 rows for 5 distinct BuNames. Bunames in primary and subreport are the same and output on both reports is ordered the same.

I want to do some calculations in my main report using the Wave1 and Wave2 fields from the main report InvCnt field from the subreport.

I've attempted to do this using shared variables.
Main report has the following formula field called MainRptVar:
Shared NumberVar x;

Sub report has the following formula field called SubRptVar:
Shared NumberVar x;
x = DistinctCount ({USOPENINV2.RMDB_Id}, {@BU});

When I run the report and place the MainRptVar in the output section it has a zero value all the time for all 5 output rows.

If I go to the subreport and run it (and include in the output the formula SubRptVar) I see that it has the value of InvCnt that I want it to have and use in the main report.

I have attempted to link the reports together based upon BuName but that doesn't work. Still get zero values.

Any ideas?

Thanks in advance!
 
The assignment operator for variables is := instead of just =. So try to rewrite your formula to the following:

Shared NumberVar x;
x := DistinctCount ({USOPENINV2.RMDB_Id}, {@BU});

 
Can you explain what you wish to calculate? If you only need to calculate using the subreport total across names, then you don't need to link, but if you need to do calculations based on group level values, then your subreport needs to be linked to the main report on name, with the subreport placed in the name group header or footer in the main report.

Also, you can only use shared variables in sections below the one in which the subreport is placed, so if it is in the report footer, insert a RF_b for the calculation formula, and if in a group, insert another section below.

If you need to add values together, you will need to add a variable in the main report to do that.

-LB
 
To answer the responses...
1)
I do have the assignment operator correct - the "=" was just a mistake in the posting.

2)
On my output I need output like following 5 columns:
BuName1 Wave1 Wave2 InvCnt InvCnt - (Wave1 + Wave2)
BuName2 Wave1 Wave2 InvCnt InvCnt - (Wave1 + Wave2)

Here is what I attempted...
1)
Created a new headers section RHb and placed my subreport in this section.

2)
Linked the main report to the subreport based upon BuName. NOTE: I didn' check the "Select data in subreport based on field" option in the Subreprot Links window.

3)
Both main and subreport showed correct numbers except for my shared variable - still returns zero.

Shared variable formula in the subreport is (variable name - ShrMainTestValue):
// Stores distinct count of invited contacts by BU in a shared variable

WhilePrintingRecords;
Shared NumberVar ShrBuInvCnt := DistinctCount ({USOPENINV2.RMDB_Id}, {@BU});

Shared variable formula in the main report is (variable name - ShrTestValue):
WhilePrintingRecords;
Shared NumberVar ShrBuInvCnt;
ShrBuInvCnt;

 
Also found that now when I preview my subreport by itself its now prompts me for a discrete BuName value. But when I enter a discrete value for BuName the preview window actually returns five rows - one for each BuName.
 
I'm working with a similar problem. The section my subreport is in is suppressed. The shared Variable is in the next group below which is not supressed but is displaying $0.00. However, once I drill down it will then display the correct dollar amount. Any way around that? The section holding the subreport must be supressed because I'm only displaying group totals(which has the shared variable amount) but I need the shared variable to do other calculations also.
I'm using CR8.5

Thanks.
L
 
First, insert a group in your main report on BUName. Then insert another group section, so that you have a GH#1a and a GH#1b. Place your subreport in GH#1a and suppress all sections within the subreport. Place your shared variable display formula:

//{@displshvar}:
whileprintingrecords;
shared numbervar ShrBuInvCnt;

...in GH#1b, along with your calculation:

//{@calc}:
whileprintingrecords;
shared numbervar ShrBuInvCnt;

ShrBuInvCnt - ({table.wave1+{table.wave2})

Your subreport should be linked to the main report on BUName, and check "select date in subreport based on field". You should also go into the section expert in the main report and for GH#1a check "Underlay following sections". Drag the wave fields from the detail section into the group header #2 section and then suppress the detail section.

-LB
 
That worked great.

If I wanted to add a second subreport should I create another GH section so I have GH#1a, GH#1b and GH#1c? Then shift my detail fields into the GH#1c section. And put all the shared variable formulas in GH#1c?

That's what I'm going to try now. If I just add my additional subreport into the current solutions GH#1a section my shared variable output for that subreport is always zero in the GH#1b section.

 
If you are getting zero for the second subreport, it is not because of sharing the section with another subreport. Make sure that you have actually placed the shared variable formula in the subreport on the subreport canvas. It could also be a linking issue--not sure, because you didn't provide specifics about the second subreport.

LLowrance,

You should probably start your own thread, but please note that you cannot suppress a main report section containing a subreport and still have the shared variables work. If you unsuppress that section and your shared variables work, then that is what the problem is. What you can do is suppress all sections WITHIN the subreport.

-LB
 
Thanks lbass,

You are correct again it was not because the subreports were sharing a section. 1) My subreport link "Select data in subreport based on field" was using the wrong value. 2) My formula for my shared variable in the subreport was incorrect - copying and pasting error.

I have one last question...

You are obviously very good with this tool. I'm sure a ton of your knowledge comes from experience but for someone like myself who for the last 6 months has had to learn by being thrown in the fire and is now able to go take some classes what classes or books would you recommend?

Classes from Business Objects or Crystal User?
Books?

Again thanks for all your help.
 
There are some standard resources: George Peck's books (I'm not sure what version he's up to). They are entitled something like "The Complete Guide to Crystal Reports x.0". Check out Ken Hamady's website (he's a participant here) and his formulas. I've probably learned most from this site and the help files themselves, and just experimenting with the Xtreme database that comes with CR.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top