How to Use a Shared Variable in a Crystal Report

Techwalla may earn compensation through affiliate links in this story.
How to Use a Shared Variable in a Crystal Report
Image Credit: AlexBrylov/iStock/Getty Images

Shared variables can be extremely useful in a Crystal Report. Unlike with local and global variables, the value stored in a shared variable can be set and/or seen anywhere in a Crystal Report. For example, you might create a shared variable called Age. You can then store the value 31 to Age in one subreport and display that value in another subreport.

Advertisement

Step 1

Set the shared variable. A shared variable can be set anywhere in the main report or anywhere in any subreport. To set a shared variable called Age you would use the following code:

Video of the Day

Shared NumberVar UserAge; UserAge := {Table1.Age}; ""

Step 2

Display or use the shared variable. A shared variable can be processed or displayed anywhere in the main report or anywhere in any subreport. You would share your Age variable like this:

Advertisement

Shared NumberVar UserAge; UserAge

Step 3

Use your shared variable in formulas or sections anywhere in your report.

Tip

Using a shared variable can help you increase the performance of a Crystal Report by allowing you to share data between subreports. This could eliminate the need to link so many tables in one subreport, thus speeding up the Crystal Report.

Advertisement

references