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

can you make a shared variable of a running total? 1

Status
Not open for further replies.

redeemasp

Programmer
Jun 1, 2004
63
GB
I'm able to make a shared variable of a data field , e.g. command.jobid,
but can you make running totals shared?

thanks
 
well Gary,

I have a selling price that is summarised within the group #1: sum of @Selling Price

I wrote the forumula to stored the summarised total into a local variable, which in turn is stored in a shared variable:

whileprintingrecords;
local numbervar sellp := Sum ({@Selling Price}, {Command.RRE_Code});
shared numbervar shdselling := sellp

I get an error on line 2, a number is required here. The number is that sum itself.

Any ideas.

Lee

 
I'm not sure why you need to set the value as local and immediately set a seperate variable to shared.

whileprintingrecords;
shared numbervar shdselling := Sum ({@Selling Price}, {Command.RRE_Code});

would give the same results.

what is it you are attempting with this formula, where does the running total come into this ?










Gary Parker
MIS Data Analyst
Manchester, England
 
What happens if you comment out the last line of the formula? What is the content of {@selling price}, and is it a number datatype, or possibly a currency datatype?

-LB
 
My report is structured in the follow way

I've 2 group:

Group 1 - job number - contains the header text.
Group 2 - code - contains the information.

I hide Group 2 for show the total sum of each code, which is displayed in Group 2 Footer.

Group 2 data contains sum of @sellingprice

also in Group 1 footer have have a sum of sellingprice.

I'm trying to make the @sellingprice in group 2 footer shared.

That's where im stuck. :(
 
Shared with what? Shared variables are only for use when using subreports. Local variables are limited to the specific formula. Global variables apply to an entire report (but not to subreports).

Are you trying to use the results from the group 2 footer in another section?

-LB
 
I've 2 sub repors in a report.

currently I've created a shared variable in sub report 1.

I want to pass that to sub report 2. getting 0's.

code is

in sub report 1:

Whileprintingrecords;
Shared currencyvar shddata_SellingPrice := Sum ({@Selling Price}, {Command.RRE_Code});


in sub report 2:

Whileprintingrecords;
shared currencyvar shddate_sellingprice
 
In which sections of the main report are the subreports ?

subreport 2 must be placed in a section after subreport 1



Gary Parker
MIS Data Analyst
Manchester, England
 
Yep sub report 1 is above sub report 2.

Actually I think it could be a sub report linking problem.

sub report 1 links to main report via job id.

my sub report 2 will be a report that is created using data from sub report 1.

now currently there is no linking between sub report 2 and main report. This is because again sub report 2 is a display only report that come from sub report 1.

Sub report 1 is link to main report via job number. How's best to link sub report 2?
 
Why are you creating a 2nd subreport just to display data from the 1st subreport ?

Gary Parker
MIS Data Analyst
Manchester, England
 
why are you creating 2nd subreport just to diaply dat form the 1st subreport ?

why not display the subreport data in the main report ?

Gary Parker
MIS Data Analyst
Manchester, England
 
well bascially there are 4 sub reports within this main report; i didn't tell u about them at the time for its wasn't relevent to my original post.

these 4 sub reports bring in data, that need to be summarised in a 5th sub report.

I wanted the data to be separate from the main report data, so I want it in sub report 5.

I was able to bring in shared job id from 1 sub report into subreport 5. I assume now that I need to link that shared job id from sub report 5 into the main report?

 
I would advise you to display the data from your subreports in a seperate section of the main report rather than creating a 5th subreport. You can not create a link between the main report and a shared variable contained within the subreport.



Gary Parker
MIS Data Analyst
Manchester, England
 
I've got a piece of data into sub report 5, from sub report 1, but it only shows the last data from the last records from sub report 1.

It seems that when it reads the main report and reads sub report 1 it will only grab the last records data, overwriting the shared variable each time, meaning I get only 1 piece of data, and not all data from each record.

this is mad.
 
if you want the subreport to display data for each job id then palec the subreports in the group footer section, this will cause them to run once for each job Id

Gary Parker
MIS Data Analyst
Manchester, England
 
Gary I appreciate the time you're giving in helping me with this problem.

The main report allows for only 1 job id.

sub report 1 reads that job id, and produces 0 are more records within it.

my example is 6 records appear. each is groups by a div id, which in this case groups as 2 records, Div J and Div K. With each of those records a shared variable is created. problem is that only records 2 shared variable data is bring passed to sub report 5.

How can I say for each record in sub report 1, pass shared data to sub report 5 for displaying.

Else can I get my results an alternative way.

pain in the ass init
 
The mist is clearing

your problem is that crystal doesn't create a new variable for each group in your report, it creates just one instance of the variable and updates it's value each time it's called that's why you only ever see the value for the last group.

If you have a limited number of division groups there could be a workaround but it's not ideal

what you need to do is assign the group values from the subreport to an array variable

i.e.

in sub report 1 page header create this formula

Code:
//@DeclareVariables
whileprintingrecords;
shared numbervar array shdselling [DistinctCount(Table.DivID})];
shared stringvar array DivID [DistinctCount(Table.DivID})];
Shared NumberVar intCount :=1

Then in the Group Header create this formula

Code:
//@Assign Values
whileprintingrecords;
shared numbervar array shdselling ;
shared stringvar array DivID ;
Shared NumberVar intCount;

shdselling[intcount] := Sum ({@Selling Price}, {Command.RRE_Code});
DivID[intCount] := {Table.DivID};

intCount :=intCount + 1

Then in the display sub report create a fromula

Code:
//@Division Display
WhilePrintingRecords;
shared numbervar array shdselling ;
shared stringvar array DivID ;
numbervar DivCount ;
StringVar Display ;

For DivCount := 1 to Count(DivID) - 1
  Do ( Display := Display + "Division " +DivID[DivCount} + " : " + ToText(shdselling[DivCount]) + chr(13) );

Display := Display + "Division " + DivID[Count(DivID)} + " : " + ToText(shdselling[Count(DivId)]);

Display

then format this field and set to can grow.

this should result in field something like

Division div 1 : 5000
Division div 2 : 7500

I haven't had chance to verify these formulas so apologies fro any syntax errors



Gary Parker
MIS Data Analyst
Manchester, England
 
Gary

I will give this a try on Monday and get back to you.

thanks again.
 
Hi Gary,

Can you explain why you have tables in the code?
e.g. [DistinctCount(Table.DivID})];

cheers

Redeem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top