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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Something weird with shared variables

Status
Not open for further replies.

Malekish

Technical User
Dec 8, 2008
36
US
There's got to be something simple I'm overlooking, I have one specific variable that seems to have quit passing it's value to my parent report.

CR XI
Subreport variables
@SPSCAban
shared numbervar SPSCAban;
If condition = 1
then
SPSCAban := sum(table.abandon)

@SPSCHandled
shared numbervar SPSCHandled;
if condition = 1
then
SPSCHandled = sum(table.handled)

@SPSCTotal
shared numbervar SPSCTotal;
SPSCTotal := @SPSCAban + @SPSCHandled

All 3 of these work correctly in my subreport, have the expected values, etc.

Parent report

@SPSCAban
shared numbervar SPSCAban;

@SPSCHandled
shared numbervar SPSCHandled;

@SPSCTotal
shared numbervar SPSCTotal;

If I put those variables in my footer (and below the appropriate subreport)
I get the expected values for Aban and Handled but Total is coming up 0 (zero). What am I missing, is it the fact that Total is a calculated field not using any tables?

I tried re-writing SPSCTotal to use the same fields, and it still fails to carry up to parent.

If condition = 1
then
SPSCTotal := sum(table.aban) + sum(table.handled)

Thanks in advance for assistance!
 
I would have done this in the subreport, all in one formula:

//{@abanhan}:
shared numbervar SPSCAban;
shared numbervar SPSCHandled;
shared numbervar SPSCTotal;
If condition = 1 then (
SPSCAban := sum(table.abandon);
SPSCHandled = sum(table.handled)
);
SPSCTotal := SPSCAban + SPSCHandled;

Also, your conditional formulas are saying: if the condition field in the last record = 1 then show the results of all records. Is this really what you mean?

-LB
 
You know, looking at the original report it's not a sum(table.field) it's just (table.field), you're correct LB and I just typed in the wrong formula.

I tried it your way, modified both parent and sub formula to follow a consistent format, I'm still not getting the desired result.

Code:
Subreport
//{@call_values}
shared numbervar SPSCAban;
shared numbervar SPSCHandled;
shared numbervar SPSCTotal;
If condition = 1 then
     (
      SPSCAban := (table.Aban);
      SPSCHandled := (table.Handled)
      )

SPSCTotal := SPSCAban + SPSCHandled;

In the parent I'm still getting 0 for value of SPSCTotal, it's not passing the value up.

I've tried defining SPSCTotal both as a seperate variable

//{@SPSCTotal}
shared numbervar SPSCTotal;

or I've tried using it as part of a formula

//{@SP Percent Abandoned}
shared numbervar SPSCAban;
shared numbervar SPSCHandled;
shared numbervar SPSCTotal;

If SPSCTotal > 0 then
SPSC Percent Abandoned := SPSCAban % SPSCTotal
else
SPSC Percent Abandoned := 0;

Excluding my typos in this post, why is it not passing the Total field up to the parent? If I declair the Aban and Handled variables in the parent and put them in my footer I get the correct value but I get 0 for the Total.

There's got to be something simple going wrong, something I'm overlooking. I'm taking an old report and adding locations to it, the formula are the same in all reports except the location code (SPSC, SPAH, SPCC, etc) and I copy/pasted the relevant formula. I've added the SC sub report from a template, just changed the names.

Thanks for your time!
 
You said the subreport was above the location you want the shared values to appear in the parent. Is the subreport in the same section as the formulas used to display the shared values?

If so, split the footer section and place the sub in footer a and the formulas in footer b
 
I am confused by your language "passing up" to the parent report. I'm assuming by parent you mean the main report, but you are actually passing down, since the subreport must be located above the section in which you reference the variables in the main report.

Please explain in what section you are placing the formulas within the subreport, where the subreport is placed in the main report (what specific section) and what section you are using when referencing the shared variables in the main report. Also identify the groups in your main report, and also explain on what fields you are linking the sub to the main report. If you are setting the shared variable to a field that varies per record, then you would expect the sub to be linked to the main report on an ID field unique to each record.

-LB
 
Hrm, I guess "passing up" is the wrong terminology. I'm viewing it from subreports "under" the parent (main) report and therefore passing the value up.

In this particular example

Parent report

Report Footer b
SubReport - Location SC

Report Footer c
Currently used to display the shared variables from subreport above, I was trying to show the numbers to troubleshoot why my values in Footer d were wrong

Report Footer d
Graphs with data from Footer b

Report Footer e
SubReport - Location AH

Continue on for all locations in same style.

In this particular case, my variables in Footer c have the expected numbers for Abandoned and Handled however the variable of Total (Aban+Handled) is 0 (zero).

If I change the variable {@SPSCTotal} to
:= {@SPSCAban} + {SPSCHandled}
then in Footer c they then revert to 0 (zero).

At this point I think I'd save myself a world of grief and time by just junking this old report and re-writing the whole thing from scratch :)

Thanks much for your time and input, it is appreciated!
 
I would NOT use formula names in your variables to reference other variables, but instead use the variables themselves.

If you run the subreport on its own, is the Total variable displaying correctly when you set it up like this:

//{@abanhan}:
shared numbervar SPSCAban;
shared numbervar SPSCHandled;
shared numbervar SPSCTotal;
If condition = 1 then (
SPSCAban := sum(table.abandon);
SPSCHandled = sum(table.handled)
);
SPSCTotal := SPSCAban + SPSCHandled;

-LB
 
Negative, something somewhere is off.

I'm thinking the re-write is really needed, this particular report was written by one person, updated by another a year later and now I get to be the new maintainer.

I can tell by the format of the various components, each had their own style and their own naming convention. Nothing is documented either (not surprising or unexpected but we can always hope).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top