Print Page | Close Window

Passing a value from SubReport to MainReport

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Report Design
Forum Discription: The best way to design a report and problems you have encountered
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=22912
Printed Date: 05 May 2024 at 12:51pm


Topic: Passing a value from SubReport to MainReport
Posted By: Emir_W
Subject: Passing a value from SubReport to MainReport
Date Posted: 15 Nov 2020 at 2:02am
I have created a report for stock transaction within a date range. And it's working fine.

And requested to add 1 column after item description with Last Qty from previous day/month.

There is a table in the system itself which contains that information (table name ItmLcDailyTotal). They are: Date, QtyBeg, PriceBeg, QtyEnd, PriceEnd.
Whenever there is a transaction for an item, it will update this table.

So, my plan is to take the QtyValue from previous date from the "Date From" and read the transactions in date range, and calculate for last final value.

I've tried with Sub-Report to take only the value from date before DateFrom and pass it to Main Report. It worked. But I cannot calculate it for final value.

e.g.:
Item R004-PH02-01, value from last month is 9.
Transactions in current month:
5 Received and 2 Sold.
In this case, Final value will be 9 + 5 - 2 = 12.

My report give me 0.

Can someone help me?

-------------
Emir W



Replies:
Posted By: Emir_W
Date Posted: 15 Nov 2020 at 2:32am
I can email you a screenshot or the CR file if needed.

-------------
Emir W


Posted By: Emir_W
Date Posted: 15 Nov 2020 at 9:00pm
I have created some variables.

Report Header
Global Numbervar TotGrpQty; //GroupTotal;
global numbervar TotQty;
shared numbervar TotGrpQty:=0;
shared numbervar TotQty:=0;

Group Header1 (Location)

Group Header2 (ItmCode)
Global Numbervar TotGrpQty; //GroupTotal;
global numbervar TotQty;
shared numbervar TotGrpQty:=0;
shared numbervar TotQty:=0;

Group Footer2
--> SubReport[StockQtyDaily]
--> Group Header (Date)
--> Group Footer
    whileprintingrecords;
    shared numbervar Totvalue:=
    {INC_ItmLcDailyTotal.DAY_QtyEnd};
    Totvalue
--> Report Footer
    Global Numbervar TotGrpQty; //GroupTotal;
    shared numbervar TotGrpQty;
    Whileprintingrecords;
    TotGrpQty := {INC_ItmLcDailyTotal.DAY_QtyEnd};
    TotGrpQty //GrandTotal
Summary for TotalTransfer; (in MainReport)
Summary for TotalDispose; (in MainReport)
Summary for TotalConsume; (in MainReport)


But it didnot work.
Did I missed something?

-------------
Emir W


Posted By: kevlray
Date Posted: 16 Nov 2020 at 4:25am
Where is your sub-report located?  Remember it has to be in a section prior to doing the calculation and it cannot be suppressed.


Posted By: Emir_W
Date Posted: 16 Nov 2020 at 9:22pm
my SubReport located in Group Footer 2 (ItmCode) and it's not suppressed.
I suppressed for GH1, GH2, Detail, and GF1.

-------------
Emir W


Posted By: Emir_W
Date Posted: 17 Nov 2020 at 2:33am
I've put my SubReport in GF2, but it didnot work. I cannot get the value from SubReport, always shows as 0 while there is a value.

Than I move my SubReport in detail section (suppress). Still no luck.

-------------
Emir W


Posted By: kevlray
Date Posted: 17 Nov 2020 at 4:28am
Double check the name of the shared variable(s) in the main report and the sub-reports.  Easy thing to overlook.


Posted By: Emir_W
Date Posted: 18 Nov 2020 at 8:09pm
I've checked all the variables in MR and SR, all same.

Here are the variables and where I put it.

Main Report - Report Header
Global Numbervar TotGrpQty;
global numbervar TotQty;
shared numbervar TotGrpQty;
shared numbervar TotQty;

Group Header2 (Suppress)
Detail (Suppress)
Group Footer2
   SubReport
      Group Header (Suppress)
      Details (Suppress)
      Group Footer (Suppress)
        global numbervar TotGrpQty;
        whileprintingrecords;
        shared numbervar TotGrpQty;{INC_ItmLcDailyTotal.DAY_QtyEnd};
        TotGrpQty
      Report Footer
        Global Numbervar TotGrpQty;
        shared numbervar TotGrpQty;
        Whileprintingrecords;
        TotGrpQty:= {INC_ItmLcDailyTotal.DAY_QtyEnd};
        TotGrpQty




-------------
Emir W


Posted By: kevlray
Date Posted: 19 Nov 2020 at 4:33am
You said that you put the sub-report in GF2?  It appears that you have GF2 suppressed, that will not work.  Sub-reports in suppressed sections do not run.


Posted By: Emir_W
Date Posted: 21 Nov 2020 at 6:51pm
In MainReport, I've put SubReport in GF2 and not suppressed. I can see the result from SubReport in Main Report, but I cannot calculate it.

So, the issue is passing the value from SubReport to MainReport in order for me to get it for calculation.


-------------
Emir W


Posted By: kevlray
Date Posted: 23 Nov 2020 at 4:05am
Maybe I got lost somewhere.  So here is the things that have to be in place for it all to work.  A shared variable(s) in the sub-report and the main report (with the same name(s)).  An unsuppressed section in the main report where the sub-report resides.  The shared variable(s) value will be available in a section after the section where the sub-report resides.

I hope this all makes sense.


Posted By: Emir_W
Date Posted: 10 Dec 2020 at 3:40am
Hi,

It fixed now.
I just realized that in one of the table there is a field that I need for the report.
So, I've created two subreports (for opening balance, and ending balance) and put it in the main report.
Now, I got the correct result.

Thank you a bunch Kevlray for your support and suggestion.

Regards,
Emir

-------------
Emir W



Print Page | Close Window