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
SOLUTION
Avatar of Mike McCracken
Mike McCracken

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Gordon Hughes
Gordon Hughes
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

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
Avatar of Mike McCracken
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
Avatar of Gordon Hughes
Gordon Hughes
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

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
Is the main report formula in the report header?

Are the 2 subreports working on the same database?

mlmcc
Avatar of Gordon Hughes
Gordon Hughes
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

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
Can you upload the rpt file?

mlmcc
Avatar of Gordon Hughes
Gordon Hughes
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

Hi mimcc

rpt file attached with data hopefully

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

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Gordon Hughes
Gordon Hughes
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

Excellent responses and solutions as always
Crystal Reports
Crystal Reports

Crystal Reports is a business intelligence application from SAP SE. It is used to graphically design data connections and report layouts from a wide range of data sources including Excel spreadsheets, Oracle, SQL Server databases and Access databases, BusinessObjects Enterprise business views, and local file-system information. Report designers can place fields from these sources on the report design surface, and can also deploy them in custom formulas (using either BASIC or Crystal's own syntax), which are then placed on the design surface. Crystal Reports also supports subreports, graphing, and a limited amount of GIS functionality.

36K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo