Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Pass shared Variable to Main report thru subreport Post Reply Post New Topic
Page  of 2 Next >>
Author Message
achandana01
Groupie
Groupie
Avatar

Joined: 20 Jul 2011
Online Status: Offline
Posts: 59
Quote achandana01 Replybullet Topic: Pass shared Variable to Main report thru subreport
    Posted: 29 Oct 2012 at 1:30pm
Hi,

In my Main report I have a summary table like this,It is grouped by FC then by Class.There is a Avg.Rev col however I get the data from a subreport as I need to use that field to calculate days for that particular class in that FC

Class-A   Avg.Rev-A    Charges           Days
Medicare(FC-A)                    
         I       subrep dat     1000   1000/Avg.Rev-A
         O       subrep dat     2000   2000/Avg.Rev-A
         ED      subrep dat     5000   5000/Avg.Rev-A
Total             subrep dat     8000   8000/Avg.Rev-A

Here is what my subreport data look like

FC        Class Charges
Medicare     I     50
Medicare     I     150
Medicare     I     100
Medicare     O     250
Medicare     O     150
Medicare     ED     200
Medicare     ED     500
Medicare     ED     200

I did group by FC then by Class to get avg. rev

FC-B     Class-B   Rev-B
Medicare          
             I     100
             O     200
             ED    300
Total              600

My initial plan is to create a shared variable in sub-report to get Avg.Rev-A field in main report however I am not sure how to pass a shared variable from sub-report to main report. can you please look into ,if there is any other way please let me know.

Thanks,

Edited by achandana01 - 30 Oct 2012 at 6:15am
chand
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 30 Oct 2012 at 8:59am
just reference the same variable in both places and it is 'passed'
in subreport
shared numbervar aValue;
aValue := ??  //will set the variable
 
in the main report
shared numbevar aValue;
aValue      //will display the variable.
 
nothing else to do.
 
typically all of this is done in a formula, one in the subreport and the other in the main.
 
HTH
IP IP Logged
achandana01
Groupie
Groupie
Avatar

Joined: 20 Jul 2011
Online Status: Offline
Posts: 59
Quote achandana01 Replybullet Posted: 30 Oct 2012 at 1:49pm
I Created shared variables exactly what you said in main report and report however I encounter a problem when I ran a report.As i Said before in my main report I grouped by FC then by Class.

In my subreport also I did the same grouping....and I put shared var in group 2 footer to get totals for Class.

Then I put my subreport in Group1 header of main report and I linked main report to subreport thru FC and Class.When I gave like this I am only getting 1stsubreport group2 values to main report for all class groups in main report group2 for that particular FC.

I removed class link and only put FC linkage to subreport.When I gave link like this I am only getting Last subreport group2 values to main report for all class groups in main report group2 for that particular FC.

I am not sure how to do the linkage to get the proper values for main report group2.

I believe I am missing a link please help!!!

Thanks,

Edited by achandana01 - 30 Oct 2012 at 2:00pm
chand
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 31 Oct 2012 at 5:51am
if you are running the subreport in group header 1, and you want it to change in group 2, it won't.
 
the subreport only runs 1 time, when group header 1 is displayed. if you want it to run for each group 2, you should move it to group header 2 and link it correctly for group 2.
 
you want the subreport to run for each group that you want to display a unique value for.
 
HTH
IP IP Logged
achandana01
Groupie
Groupie
Avatar

Joined: 20 Jul 2011
Online Status: Offline
Posts: 59
Quote achandana01 Replybullet Posted: 31 Oct 2012 at 1:14pm
In my subreport I only created a group for group2 and I put it in main report Group2 header and its working fine.

I need to do a sum of all value in group2 to put that value in main report group1 footer is it possible to do a sum or do I need to create another subreport for group1 to get the total value for group1 ? or is there any other way to do ?

Edited by achandana01 - 31 Oct 2012 at 1:15pm
chand
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 31 Oct 2012 at 1:22pm
if you want the sum in the group header1, then I would create a new subreport / modify the existing subreport to give the total that you are after.
 
if you can display the total in the group footer1, then you could create your own total:
 
shared numbervar aTotal;
shared numbervar aSubreport;
aTotal := aTotal + aSubreport;
""//will hide the running total
 
of course you would substitute your subreport variable.  Then when you want to display the total, you would of course, write a formula like:
shared numbervar aTotal;
aTotal
 
HTH
IP IP Logged
achandana01
Groupie
Groupie
Avatar

Joined: 20 Jul 2011
Online Status: Offline
Posts: 59
Quote achandana01 Replybullet Posted: 31 Oct 2012 at 6:31pm
I created a formula

Shared numbervar aTotal ;
aTotal := aTotal + {#Group 2 Charges}

//I am getting charges for group2 from the running total above

I created another formula in main report
Shared numbervar aTotal;
aTotal

I used this in report footer and I am getting correct grand total for the report.However I also need totals for data in Group1.Using the above formula I could able to get grand total in report footer but I am not able to reset shared variable in group footer 1 if so I could able to get what I am looking for.

It will be easier for me if I could create a formula for the totals for Group1 with in th same report rather than creating another subreport.

Thanks

Edited by achandana01 - 01 Nov 2012 at 6:00am
chand
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 01 Nov 2012 at 7:03am
have another variable for the group1
shared numbervar agroup1;
 
create a formla like:
shared numbervar agroup1;
agroup1 := 0;
""//will hide the resulting 0
 
place the formula in the group header 1...this will reset the group 1 total
add another line to :
Shared numbervar aTotal ;
shared numbervar agroup1;
agroup1 := agroup1 +{#Group 2 Charges};
aTotal := aTotal + {#Group 2 Charges}
 
that's all you need...and of course a display formula, but you already know how to do that.
IP IP Logged
achandana01
Groupie
Groupie
Avatar

Joined: 20 Jul 2011
Online Status: Offline
Posts: 59
Quote achandana01 Replybullet Posted: 01 Nov 2012 at 1:10pm
Excellent!! Its working for me you are a master [IMG]smileys/smiley1.gif" align="middle" />

I have another question I also do need to calculate % for each group typically this should me the formula

Total Charges GF2/Total Charges RF
Total Charges GF1/Total Charges RF

However I am having a problem to do this kind of % calculation for shared variables in groups, when I put the RF formula it is giving erroneous result.



Edited by achandana01 - 01 Nov 2012 at 1:11pm
chand
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 02 Nov 2012 at 5:53am
typically for formulas that are not producing the desired values, I will create multiple formulas and display them, like:
one for Total Charges GF2
and one for Total Charges RF
and then compare the result to Total Charges GF2/Total Charges RF
same for the GF1
so that I can 'see' what CR is doing.
 
HTH
IP IP Logged
Page  of 2 Next >>
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.016 seconds.