Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shared variable yields 0

Status
Not open for further replies.

gbuchman1

Technical User
Mar 8, 2010
60
US
Hi,
I created a subreport that calculates a value using a formula. I then shared this value with my main report by making it a shared variable. However, the shared variable always shows as 0 in every area of the main report. It shows correctly however on the subreport.

Here are the details: the main report yields account values for 24 cost centers for each of 100 account numbers. So the report is a large grid. The subreport is a mini version of the main report in that it gives account values for 24 cost centers for one account number. Then it calculates the percentage of the total for each cost center. It is this percentage figure that is my shared variable that I want to use on the main report in formulas. There is one formula for each of the 24 cost centers and I actually will have 24 shared variables; one for each of the cost centers.

The subreport is in the group header (the group is account number) and the reports are linked by account number. I did create a shared numberVar for each of the 24 percentages from the subreport. But it always shows as zero and therefore doesnt do the calculation I need done.

Even if I show the account from the subreport on the main report, the formula STILL shows as zero. I declared the first variable on the main report like this:

whileprintingrecords;
shared numberVar A;
SUM({%A Edison AT4009}, {tblGLBLBalance.sCodeIDf_0}) +
A * {@AmtAllocbyGL}

I declared the variable in the subreport like this:

whileprintingrecords;
shared numbervar A := {@PercentEdison}

{@PercentEdison} is the formula that yields the desired percentage.

Please assist me with this annoying problem. Thanks!
 
Thanks for not giving up on this! I removing one of the groups from the sub and that still runs fine. I also changed the @AmtEdisonbyGL formula to read:

whileprintingrecords;
shared numberVar A;
SUM({%A Edison AT4009}, {tblGLBLBalance.sCodeIDf_0}) +
shared numberVar A * {@AmtAllocbyGL}

Is this what you mean by identifying the variable as shared, in all formulas?

I also changed the formula @EdisonSharedPct in the main report:

shared numberVar A := A to be

whileprintingrecords;
shared numberVar A := A

Still no good.

I have not suppressed the subreport or suppressed or hidden the section the subreport is in. Unfortunately, even after doing all this, I still get 0 in the main report. Im at a loss to know what else to do here.
 
No that's not what I meant.

//in the sub:
whileprintingrecords;
shared numberVar A;
SUM({%A Edison AT4009}, {tblGLBLBalance.sCodeIDf_0}) +
A * {@AmtAllocbyGL}


//reference in the main report:
whileprintingrecords;
shared numberVar A;

...should be fine. The main report formula must be in a section below the one containing the sub.

If you place the sub in RH_a do you see the correct value IN the sub in the footer?

-LB
 
When I place the sub in RH, yes, I do see the correct number in the sub in the footer (of the sub). I cannot set the formula in the sub the way you said however because the @AmtAllocbyGL only exits in the main.

So in the sub I have @PercentEdison as:

ROUND (({@AmtEdisonbyGL-1} / {@All499901-Allocated}),4)

and then below that is @PercentEdison-1 as:

whileprintingrecords;
shared numbervar A := {@PercentEdison}

Then in the main report, GH1 I have @EdisonSharedPct which is:

whileprintingrecords;
shared numberVar A;

and then in GF2 of main is @AmtEdisonbyGL which is:

whileprintingrecords;
shared numberVar A;
SUM({%A Edison AT4009}, {tblGLBLBalance.sCodeIDf_0}) +
A * {@AmtAllocbyGL}

This should work, shouldn't it?
 
Yes. So I guess you are seeing the correct value for {@PercentEdison-1} in the subreport footer.

And do you see the same value in {@EdisonSharedPct} in GH1 of the main report? If you only see a zero, be sure to format it to show the decimals.

If everything is working to this point, then comment out parts of your GF2 formula to see which part isn't working.

-LB
 
For @EdisonSharedPct in the GH1 of the main report, it still yields a value of .0000 This is because I formatted the field to show 4 decimal places, rounded to the nearest ten thousandth, and to not show the leading zero. What is so frustrating is why the decimal value it is supposed to have of .0676 does not show.

I commented out one section at a time of the @AmtEdisonbyGL formula and I still get .0000 each time.

Please note that although this is one shared variable, my goal is to make 23 more like it - one for each of 24 columns in this report - once I get this one for Edison to work. If one works, then the other 23 will work since they will all be setup the same way.
 
With the sub in the report header, you are no longer linking it to the main report, correct? And ARE you seeing the correct value in the subreport footer when you run the main report?

-LB
 
Correct, I am no longer linking the sub to the main. And yes, I am seeing the correct value in the subreport footer when I run the main. What you said here gave me an idea; I went to the subreport, right-clicked and chose Format Subreport and went to the Subreport tab. There I unmarked "On-demand subreport" so that the contents of the subreport would show. Up to now, it had been set to "On-demand subreport". Once I unmarked this, THEN the correct values finally showed up in the GH1! Wow, what a relief! Thank you so much! The total at the bottom of the first column where I had set up my formulas now looks correct. I will look more carefully with this and see if I can now set up formulas in a few more columns to be sure that they work too. Will let you know what I find. You made my day, LB! Thanks so very much!!
 
Did you say that anywhere--that it was an on-demand report?

Anyway, if you don't want the sub to show, you can suppress all sections WITHIN the subreport, remove the border from the sub, go to format->sub->subreport tab->check "suppress blank subreport". If you don't want the report header section to show, format it to "suppress blank section". The shared variable will still pass--along as the subreport object or the section it is in are not suppressed.

-LB
 
I ended making the 24 shared variables from the one subreport and all worked well. Showing the subreport did the trick. The report now looks great and does just what I want it to do. Thank you again, LB, for your terrific guidance and help!
 
Note that I was able to suppress all sections within the subreport, remove the borders, and marked "suppress blank subreport", as you advised. This caused the report to be hidden but still allowed the variables to pass to the main report, just what I wanted. Many thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top