Avatar of Gordon Hughes
Gordon HughesFlag for United Kingdom of Great Britain and Northern Ireland asked on

Carry Data between 2 sub reports

I have a report where I want to carry data from 1 sub report to a 2nd sub report
Thought I was there with the following formula

WhilePrintingRecords;
Shared NumberVar MyValue2;

Shared StringVar Array loc_names;
Shared NumberVar Array loc_totals;
Shared NumberVar loc_count;
Local NumberVar i;

if {WOEQLIST.LOCATION} in loc_names then
(
// If LOCATION is in the loc_names array, find which entry it's in
// and then output the corresponding entry from loc_totals
  for i := 1 to loc_count do
    if loc_names [ i ] = {WOEQLIST.LOCATION} then
      exit for;
  loc_totals [ i ]
)
else
// If LOCATION is not in the loc_names array, just output 0
  0

but it is not carrying all the figures forward as can be seen in the attached
Am sure it just requires a slight mod to the formula
Please help

Gordon
Carry-Forward-figures.pdf
Crystal Reports

Avatar of undefined
Last Comment
Gordon Hughes

8/22/2022 - Mon
SOLUTION
Mike McCracken

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
Gordon Hughes

Hi mimcc

James helped with this
In the 1st sub report there is:
WhilePrintingRecords;
Shared NumberVar MyValue2;

Shared StringVar Array loc_names;
Shared NumberVar Array loc_totals;
Shared NumberVar loc_count;
Local NumberVar i;

MyValue2 := Sum ({@NoDoneInPeriod}, {WOEQLIST.LOCATION});

if loc_count > 0 and {WOEQLIST.LOCATION} in loc_names then
(
// If LOCATION is in the loc_names array, find which entry it's in
// and then add the Sum to the corresponding entry in loc_totals
  for i := 1 to loc_count do
    if loc_names [ i ] = {WOEQLIST.LOCATION} then
      exit for;
  loc_totals [ i ] := loc_totals [ i ] + Sum ({@NoDoneInPeriod}, {WOEQLIST.LOCATION});
)
else
(
// If LOCATION is not in the loc_names array, increment the count,
// resize (Redim) the array to match (Preserve keeps the existing
// array contents), and put LOCATION and the Sum in the last entries
  loc_count := loc_count + 1;
  Redim Preserve loc_names [ loc_count ];
  Redim Preserve loc_totals [ loc_count ];
  loc_names [ loc_count ] := {WOEQLIST.LOCATION};
  loc_totals [ loc_count ] := Sum ({@NoDoneInPeriod}, {WOEQLIST.LOCATION});
);

In the second report can only see
WhilePrintingRecords;
Shared NumberVar MyValue2;

Shared StringVar Array loc_names;
Shared NumberVar Array loc_totals;
Shared NumberVar loc_count;
Local NumberVar i;

if {WOEQLIST.LOCATION} in loc_names then
(
// If LOCATION is in the loc_names array, find which entry it's in
// and then output the corresponding entry from loc_totals
  for i := 1 to loc_count do
    if loc_names [ i ] = {WOEQLIST.LOCATION} then
      exit for;
  loc_totals [ i ]
)
else
// If LOCATION is not in the loc_names array, just output 0
  0


Does this make sense or is something missing
Gordon
Mike McCracken

You need to also declare the shared variables in the main report otherwise there is no way carry the value through the main report from the 1st to the second subreport.

Since the subreports cannot communicate with each other directly the main report is used to carry the information from one to the other.  If it has no where to save the information then it cannot be given to the 2nd subreport.

mlmcc
ASKER
Gordon Hughes

Hi mimcc

I have addedthe 2 formulae
1 in the main report and 1 in the 2nd sub report
I still get the 0 values

Gordon
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Mike McCracken

Is the main report formula in the report header?

Are the 2 subreports working on the same database?

mlmcc
ASKER
Gordon Hughes

Hi mimcc

I put  the following in the main report
WhilePrintingRecords;
Shared NumberVar MyValue2;

Shared StringVar Array loc_names;
Shared NumberVar Array loc_totals;
Shared NumberVar loc_count;

And yes they all look at the same database

Gordon
Mike McCracken

Can you upload the rpt file?

mlmcc
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
Gordon Hughes

Hi mimcc

rpt file attached with data hopefully

Gordon
Weekly-KPI-Report-Version-2a.rpt
ASKER CERTIFIED SOLUTION
James0628

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
Gordon Hughes

Excellent responses and solutions as always