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

CR 8.5 pass data back from Subreport for calculation in Main report

Status
Not open for further replies.

gal

Programmer
Mar 5, 2002
25
US
In a CR 8.5 Subreport I need to subtotal table data into 12 formula fields and pass the summarized data back to the Main report to to be used in calculations.

The reason: The data cannot be summarized as required at the group levels because the 12 fields are independent of the groupings. The Summarized fields will be used as coefficients in manual cross-tabulations. They change regularly so hard-coding would be unworkable. Thank you very much.
 
Create formulas for the data to be passed back to the main report using shared variables.

Define formulas in the main report that declares the same shared variables, but do not set a value in the main report.

MrBill
 
Thank you. I didn't know they existed. Help says, "Shared variables (Crystal syntax)
Shared variables use the same memory block to store the value of a variable throughout the main report and all of its subreports. Thus shared variables are even more general than global variables. To use a shared variable, declare it in a formula in the main report as in the following example:

Shared NumberVar x := 1000;

and declare it in a formula in the subreport as in the following example:

Shared NumberVar x;

In order to use shared variables, the variable must be declared and assigned a value before it can be passed between the main report and the subreport." I'll try it.
 
Dear Gal,

The help, while convoluted is indicating that you need three formulas. Think of them as Initiate, Evaluate, and Display. I actually add that to the end of the formula so I know which I am referencing.

//01_ABC_INIT - Placement Main report where
value is to be initialzed (reset).

Shared Numbervar X := 0'
x
//

//01_ABC_EVAL - Placement Subreport
//group footer for example.
shared Numbervar X;

X := sum({Table.Myfield},{Table.FieldGroupedOn});
x
//

//01_ABC_DISP - Placement Main Report below subreport
//where where values accumulated
//where I want to display value of x or use value of x
Shared Numbervar X;
x
//

Hope that helps,

ro

Rosemary Lieberman
rosemary-at-microflo.com, Microflo provides expert consulting on MagicTSD and Crystal Reports.

You will get answers more quickly if you read this before posting: faq149-3762
 
Thank you for your explanation. Is it possible to use "if statements" within the formulas in the subreport? Will it work if you say something like,

shared Numbervar x;

if A = B
then
x:=sum({Table.Myfield},{Table.FieldGroupedOn});

x <====is this part of the required code or does it indicate a field that is displayed at this level {Table.FieldGroupedOn})?

 
Dear Gal,

I have developed habits from many years of report writing. One of those habits is that if the result of my formula is the variable I assigned a value to, I call the variable. I have seen instances where simply ending with:

X := if A = B
then
sum({Table.Myfield},{Table.FieldGroupedOn})
else 0;

for example may not return as expected. However, if I call the variable I just assigned the value to, it does.

Numbervar MyValue;
MyValue := if A = B
then
sum({Table.Myfield},{Table.FieldGroupedOn})
else 0;
MyValue


You can do if statements, loops, and all kinds of things, and you can do exactly what you showed in your example.

I tend to do mine as shown in the change to your example and again, a habit ....

Read the information in the help on variables ... they have requirements:

Scope - Where can I be used.
Global. Default if not declared. Means anywhere in the report, but not in subreports.
Local. This formula only. Allows you to reuse variable names over and over again in multiple formulas in the same report.
Shared. Can be used in the main report (global +) any subreports.

Datatype - What type of value? Number, boolean, date, datetime and so on ... declared as NumberVar, BooleanVar and so on.
Assignment operator for the value it has is a := (that is a colon equals sign with no space in between).

Statement separator. Statements are ended with a semicolon.

Name - Cannot use any keywords, functions, etc. If it turns blue can't use it.

There are no public variables. You must redeclare the variable in your formula each time you want to use the variable and you cannot change datatypes of a variable from formula to formula.

Variables are great, they make formulas easier to write and read ... enjoy.

regards,

ro



Rosemary Lieberman
rosemary-at-microflo.com, Microflo provides expert consulting on MagicTSD and Crystal Reports.

You will get answers more quickly if you read this before posting: faq149-3762
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top