Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Passing shared variable from subreport back to main

Posted on 2013-11-17
10
Medium Priority
?
795 Views
Last Modified: 2013-11-19
I have a main report running several sub reports.  I would like the value of a sum field (actually a sum of a formula field) calculated in the sub report to be passed back to the main for use in another formula in the main.

In main I have a formula field called subtotal_percap

WhilePrintingRecords;
Shared NumberVar subtotal_percap;
 
In the sub I have the identically named formula field,

WhilePrintingRecords;
Shared NumberVar subtotal_percap;
subtotal_percap := 99.99;

I have tried a few things, including this last line - 99.99, just to see if the 99.99 can get passed back to main, and it doesn't.   I'd actually prefer to have the sum field passed back to main.    The sum field I'd like to use is

Sum ({@sum_by_status})


Based on what I saw in other postings here on EE, it looks like I'm doing this right, but @subtotal_percap  on the main doesn't show 99.99, it just shows 0.00.

What am I doing wrong?  And, what would be the correct syntax to capture the
Sum ({@sum_by_status}) in the shared variable for passing?
 

thanks

dave
0
Comment
Question by:fhcdaver
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 101

Accepted Solution

by:
mlmcc earned 1600 total points
ID: 39655216
The subreport is the last thing evaluated in a section so if the subreport is inthe same section with the formula in the main report, the main report formula is evaluated then the subreport is called.  

Try this

in the Main report add a formula to the report header.

WhilePrintingRecords;
Shared NumberVar subtotal_percap;
""

In the subreport use your formula
WhilePrintingRecords;
Shared NumberVar subtotal_percap;
subtotal_percap := 99.99;

or the one you really want
WhilePrintingRecords;
Shared NumberVar subtotal_percap;
subtotal_percap := Sum ({@sum_by_status});


in the main report in a section after the subreport use your formula
WhilePrintingRecords;
Shared NumberVar subtotal_percap;
subtotal_percap

If you need to dislay the value in the same section then
1.  Have the subreport display it
2.  Insert a section below the subreport section and disply it there
3.  Insert a section below the subeport and move everything from the main report section other than the subreport to the new section

mlmcc
0
 

Author Comment

by:fhcdaver
ID: 39655259
OK I will try that.  
In the report header, then, I would have a formula field called "@dummy" or something equivalent. Then in the main, in a section following the sub, I'd reference another formula field, maybe named "@the_real_thing".  Both formula fields can reference the same shared variable?  


additonally, to elaborate a bit:
The report has several detail sections (detail a, detail b, etc).   This sub report is in detail b.
You're suggesting that I put @the_real_thing perhaps in detail c?
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 39655315
That is correct if you want it displayed in the detail section

mlmcc
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:fhcdaver
ID: 39656777
Hi,

almost there.   I can see the 99.99 in a subsequent detail section.

When I use this in my subreport

WhilePrintingRecords;
Shared NumberVar subtotal_percap;
subtotal_percap := Sum ({@sum_by_status});

crystal complains and says "a number is required here. "
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 39657587
What is the formula @sum_by_status - by its name it should be a number but it could be anything

mlmcc
0
 

Author Comment

by:fhcdaver
ID: 39657764
It is a report footer sum of a currency field.
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 39657883
Crystal will not do any automatic type conversion.  I know to use a Currency value looks like a number but it is a different data type

Try this formula

WhilePrintingRecords;
Shared CurrencyVar  subtotal_percap;
subtotal_percap := Sum ({@sum_by_status});

Open in new window


Note the change in type to CurrencyVar

mlmcc
0
 
LVL 35

Assisted Solution

by:James0628
James0628 earned 400 total points
ID: 39659038
If you change the variable type to currency, you'll need to change it in every formula that uses that variable, in the main report and the subreport.

 Unless you really need the summary to be the currency data type, it might be easier to just convert the currency summary to a number:

WhilePrintingRecords;
Shared NumberVar subtotal_percap;
subtotal_percap := ToNumber (Sum ({@sum_by_status}))


 James
0
 

Author Comment

by:fhcdaver
ID: 39660709
Thanks mlmcc and James.  you both hit  it.    

What I did was in the sub report I added the ToNumber function as James suggested.    So it became a number when it was passed back "up" to the main report.  

(p.s.:  mlmcc, I see your byline everywhere  here in EE when to comes to Crystal.  Very cool. )
0
 

Author Closing Comment

by:fhcdaver
ID: 39660717
Shared effort, shared solution.   thanks to you both.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question