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!

Pass Totals from Sub report to Main report for computing in Main

Status
Not open for further replies.

gal

Programmer
Mar 5, 2002
25
0
0
US
Using CR 8.5 the objective is basically to pass the Final Total # Beds in each hospital (e.g., Hospital A and Hospital B) from the Sub report to the Main report.

The Final Total # Beds for each hospital is used as a coefficient in calculations at multiple Group levels in the Main report. Hospitals are manually cross-tabulated horizontally across the page. Group-1 is Age group. Groups 2-4 also use the Final Total # Beds in calculations. Because the # Beds need to be totalled differently than the groups allow, I don't see a way to do this in a single report.

So, I created Shared Variables in the Main report called SharedBedsKid coded as ( Shared NumberVar x; ) and
SharedBedsGeri coded as ( Shared NumberVar x; )

I created same-name Shared Variables in the Sub report but used criteria to define the values. In the Sub report, SharedBedsKid is coded as
( if {Table_Bed_Capacity.Hospital} = “A”
then
Shared NumberVar x := Sum ({Table_Bed_Capacity.Beds}, {@AgeGroupByProgram}) ).

Also in the Sub report, SharedBedsGeri is coded as
( if {Table_Bed_Capacity.Hospital} = "B"
then
Shared NumberVar x := Sum ({Table_Bed_Capacity.Beds}, {@AgeGroupByProgram}) ).

Where {@AgeGroupByProgram} is defined as:
( if { Table_Bed_Capacity.program } = "441" then "Geriatric Patients"
else
if { Table_Bed_Capacity.program } = "486" then "Kid Patients"
else
"Adult Patients" )

Main-to-Sub report Linkage is by the effective date of bed capacity. That is sufficient to find the effective Bed Capacity records for the month for each category of patient.

The correct values show in the Sub report, but the Main report only shows zeroes. What can I do to get the Final Total # Beds into the Main report? Your assistance will be much appreciated.
 
Where is the subreport within the main report?

The concept is generally that if you have a subreport (which is generally a bad idea if it can be avoided), then any use of the subreport shared variables is only available AFTER the section in which the subreport exists.

A common situation might be that a subreport exists in group header 1, and is required for a formula in the details.

So an additional section (right click the section and select insert section below) would be inserted , and the subreport would go in Group Header 1B and in the groupheader 1 A a reset formula would be inserted:

whileprintingrecords;
shared numbervar SomeTotal:=0

In the subreport you'd set the value:

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

Then in the Group Footer or in the details you could then reference the shared variable:

whileprintingrecords;
shared numbervar SomeTotal;
SomeToal/12

Hope this helps to understand how they work.

-k
 
Thank you, synapsevampire, for your very helpful explanation. I will move the Sub report to the heading because I don't see a way around needing a Sub report. I will also follow your additional suggestions. Two more questions, please:

Is SomeTotal the Shared variable name in your example--so that it is referencing itself?

May I qualify what I want to include as belonging in that variable, such as if the patient is in the right program? Such as...

whileprintingrecords;
if { Table_Bed_Capacity.program } = "486"
then
shared numbervar SomeTotal:=sum({table.field})
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top