Crystal Report allows seven types of variables (Number, Currency, String, Date, Time, DateTime and Boolean) declared using one of three scopes (Local, Global and Shared). The variables can be used for processing information on your main report as well as creating complex formulas using subreports. However, the scope type chosen and the order of the variables determines how they are used.
Global Variables
This is the default scope for variables and is what will be used if you do not declare a scope. For example StringVar y and Global StringVar y are the same scope. A global variable is one that will hold the same value throughout the report it is being used on, but will not be passed to any subreports. If being used on a sub-report, the variable value will not be shared with the main report.
Local Variables
This type of variable will only be used in the formula that is declaring it. In addition, they will only retain their value for a single evaluation.
For example:
Local NumberVar x;
x := x +10;
will equal 10 for every record. If declared as a Global Variable, it would add 10 for every record.
Shared Variables
This type of variable will always retain its value not only on the main report, but also on subreports and in every formula that declares the variable. These are most useful when the main report is going to display a value that is a total of values from a subreport.
Variable Processing
When processing variables within formulas, it is important to remember that Crystal Reports processes from top to bottom. This means that if you are using a shared variable to aggregate data on a subreport in the report details, the total value will not be correct in the report header. With the exception of Local variables, any variable declared with the same name will be considered to be the same variable. If you declare two different Shared or Global variables with the same name but different variable type (eg. NumberVar and StringVar) this will cause an error on your report.
Comments
0 comments
Please sign in to leave a comment.