Solved

Crystal Report Shared Variable bring 0s

Posted on 2011-09-15
8
318 Views
Last Modified: 2012-05-12
I have a sub reports named sub_1. I got the sum value and created an shared variable [sum], and try to bring back to the main report and put in the detail section.

Sub_report->[Share_Variable_ Prior_Lease_Year_Sales]
shared NumberVar Prior_Lease_Year_Sales={sum}

Mian report->[Share_Variable_ Prior_Lease_Year_Sales]
WhilePrintingRecords;
shared NumberVar Prior_Lease_Year_Sales;
Prior_Lease_Year_Sales;

I put the shared variable in the detial section of main report  and link them by [sale_id]
1. I found out the first value of share variable always gives 0. which the actual value is not 0. and also realize that the correct value always offset one row.
2. Also, If the there is no value return from the subreport shared variable, then in the main report, that record willl read the previous's share variable's value. I want to see 0 if there is no value return.

How can I fix issue 1 and 2.

Thanks in advance!
0
Comment
Question by:FinghtingMiao
  • 6
8 Comments
 

Author Comment

by:FinghtingMiao
Comment Utility
I already figure out the issue 2 just use reset to 0 for each record.
But is anyone can help me on issue1?
Thank you a lot.
0
 
LVL 100

Accepted Solution

by:
mlmcc earned 500 total points
Comment Utility
The subreport has to be in a section before the main report usage.

Where is the main report formula?

You may have to add extra sections
Right click the detail section in the left margin
Click INSERT SECTION BELOW
There is no a details A and B
Details A can have the subreport while details B can have the main report formula.

All main report formulas are evaluated before a subreport is evaluated in the section.

mlmcc
0
 

Author Comment

by:FinghtingMiao
Comment Utility
mlmcc:
The solotion u provided works! But the @reset does not work any more.
@reset
whileprintingrecords;
NumberVar Prior_Lease_Year_Sales:=0;

I put  it in the main report, and no matter where I put it, the Prior_Lease_Year_Sales sitll display last record(sale id)'s value if the subreport return no data. But what I am lookin for is: If subreport bring no data for this record, the Prior_Lease_Year_Sales should display 0.

Thanks again!
0
 

Author Comment

by:FinghtingMiao
Comment Utility
SOrry, I got the answer! I just miss-spell the variable name.

Thank you!
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:FinghtingMiao
Comment Utility
I've requested that this question be closed as follows:

Accepted answer: 0 points for FinghtingMiao's comment http:/Q_27311024.html#36550230
Assisted answer: 500 points for mlmcc's comment http:/Q_27311024.html#36546591

for the following reason:

thank you. It is a good tip I should keep in mind if use shared variable in crystal report
0
 

Author Comment

by:FinghtingMiao
Comment Utility
Miss type
0
 

Author Closing Comment

by:FinghtingMiao
Comment Utility
thank you. It is a good tip I should keep in mind if use shared variable in crystal report
0
 
LVL 34

Expert Comment

by:James0628
Comment Utility
 > I just miss-spell the variable name.

 You have to be very careful about that.  CR doesn't try to do any cross-checking or anything like that.  If you mis-type a variable name, you just create a new variable.  I will often copy variable declarations from one formula and paste them into other formulas, to make sure I get the names correct (and just to save some typing :-).

 You also need to be careful about the variable types - Local, Global and Shared.  They're all separate.  If you declare a Shared variable in one formula and a Local variable with the same name in another formula, those are two separate variables.  You have to make sure that the names and types are consistent.

 James
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now