We help IT Professionals succeed at work.

Crystal Reports 10 Shared Variable Problem - Please Assist!

716 Views
Last Modified: 2013-11-15
I am developing a report using Crystal Reports 10 and I'm having a problem with a shared variable in the report.
The report contains 3 sub-reports and is laid out as follows:
 Group Header1     <- placed formula field w/ shared variable here
 Detail a  <- Subreport1 (contains formula field which updates shared variable)
 Detail b  <- formula field to display contents of shared variable
 Detail c  <- Subreport2 (contains formula field which updates shared variable)
 Detail d  <- formula field to display contents of shared variable
 Group Footer1 <- placed formula field to reset shared variable

In the main report I created a formula field named "NoAction" which looks like this:
 WhilePrintingRecords;
 Shared BooleanVar NO_ACTION;

I placed the "NoAction" field in the main report's group header 1.

Subreport1 resides in the Da band. In the group footer of Subreport1 I have a formula field called "set_action_flag" which looks like this:
 WhilePrintingRecords;
 Shared BooleanVar NO_ACTION;
 If Sum({@action_qualifier}) = 0 Then
   NO_ACTION := Yes
 Else
  NO_ACTION := No

I'm using the Db band for debug purposes just to check the value of the shared variable after Subreport1 finishes updating it. I have the "NoAction" formula field placed here to check this.

Subreport2 resides in the Dc band. In the report footer of Subreport2 I have a formula field also called "set_action_flag" which looks like this:
 WhilePrintingRecords;
 Shared BooleanVar NO_ACTION;
 If NO_ACTION = True and Sum({@action_qualifier}) > 0 Then
   NO_ACTION := False

Again, I'm using the Dd band for debug purposes just to check the value of the shared variable after Subreport2 finishes it's processing. The "NoAction" formula field has been placed here as well.

Here is the issue I'm having. When I'm previewing the report I can see that the value of the "NoAction" field is initially FALSE in the report group header. For a particular record, it is then set to TRUE within Subreport1 and I am able to verify this in the main report's Db band. This seems to be working great. Within the Dc band (Subreport2), I can see that it still has a value of TRUE in the subreport's header section. The value is then set back to FALSE in the report footer of Subreport2. However, the shared variable is showing a value of TRUE in the main report's Dd band where I have the "NoAction" formula field placed as a check!
Unless I am missing something, should'nt it have remained as FALSE?
If anyone can help clear this up for me, it would be greatly appreciated!

Thanks Very Much!
Comment
Watch Question

Mike McCrackenSenior Consultant
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2013

Commented:
Did you cut and paste the formulas or retypr them?

What are the formulas in Db and Dd for display.

mlmcc

Author

Commented:
mlmc:

Once the initial formula fields were created, I dragged them onto the report from the field explorer. Of course, I had to re-type them when creating the subreports. Is this what you are asking?

I'm only using Db and Dd for debug purposes. They will be suppressed or removed in the final product. I inserted them so that I could see what the shared variable value is in the main report.

The formula field I'm placing in Db and Dd is the "NoAction" field.
  WhilePrintingRecords;
  Shared BooleanVar NO_ACTION;

Thanks!
Mike McCrackenSenior Consultant
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2013

Commented:
N, I meant did you cut and paste them to the question here or retype them?

mlmcc

Author

Commented:
mlmcc

Yes, I copied them from the report and pasted them here.
Mike McCrackenSenior Consultant
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2013

Commented:
They look correct, just wanted to be sure there wasn't a typo in one of them

mlmcc

Author

Commented:


I was actually hoping that you had noticed a typo or some sort of syntax problem...
That would have made this easy.

This is really driving me crazy.

Could it be that you are not allowed to use the same formula field names which reference a shared variable within two separate subreports? I will check this...
Mike McCrackenSenior Consultant
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2013

Commented:
No, I've done that many times.

Can you upload th ereport file with saved data?
Make a copy and change the extension to txt

mlmcc

Author

Commented:
mlmcc

Sorry, I can not do that.
The data contains sensitive information.
Mike McCrackenSenior Consultant
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2013

Commented:
Upload the report itself with no data.  I can at least see the formulas and layout.

mlmcc

Author

Commented:


Here you go. (See attached file)

Thanks!

Draft.txt
Mike McCrackenSenior Consultant
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2013

Commented:
Try changing your ({@action_qualifier}) formula in the subreports

WhileReadingRecords;
 If IsNull({event_ledger.caa49540004}) then
    0
 else If ({event_ledger.caa49540004} in [5680,5684,5690,5691,5692,5693,5695]) Then
   1
 Else
   0

If that doesn't work try removing the WhileReadingRecords line

mlmcc

Author

Commented:


No luck. I tried both suggestions:
WhileReadingRecords;
If IsNull({event_ledger.caa49540004}) then
   0
Else
   If ({event_ledger.caa49540004} in [5680,5684,5690,5691,5692,5693,5695]) Then
      1
   Else
      0

and

//WhileReadingRecords;
If IsNull({event_ledger.caa49540004}) then
   0
Else
   If ({event_ledger.caa49540004} in [5680,5684,5690,5691,5692,5693,5695]) Then
      1
   Else
      0

I have attached a screenshot showing output for a single record and what's happening.

Any other ideas?

screenshot.jpg
Senior Consultant
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2013
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:


Okay, great! That did the trick!
The question is why?

See attached screenshot (red text indicates separate Flag1, Flag2, Flag3 formulas)

screenshot2.jpg
Mike McCrackenSenior Consultant
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2013

Commented:
No idea unless because it has been evaluated in the section, it doesn't reevaluate.

mlmcc

Author

Commented:
Thanks very much for hangin-in there to get this resolved!
I appreciate the time and assistance.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.