Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3223
  • Last Modified:

How to populate a global crystal variable while reading records

Hello,
I have a crystal report where I want to create some variables that are global to the report and then populate them while reading records. I did this once about 5 years ago and I completey forget how to do it...also where do I place the formula that sets the variables and how do I access them later?

I should clarify a bit though,

I have a table that holds true false values for conditional formatting of the report. The report itself is returning customer information in a single row, but then linked to a table that has multiple rows that link via a Document ID. The SQL query returns as many rows as there is conditional formatting items in the application. This results in let's say 20 rows of the same customer information + the conditional formats id number and wether it is on or off.

seen here
ADDRESS, USER, AMT, CITY, ZIP, JOB, DOCUMENTID, ITEMID, ON/OFF
55 Water Street  ,Administrator  ,10510.88 , New York,NY,10048,21,92 ,89 ,0
55 Water Street  ,Administrator  ,10510.88 , New York,NY,10048,21,92 ,90 ,1

I wanted to create a variable for each ITEMID, and set it to true or false so that later in the report if there are boxes that need an X or if I need to show or hide certains sections I could use a supress formula and look at that global variable....




Thanks
0
melegant99
Asked:
melegant99
  • 4
  • 2
2 Solutions
 
James0628Commented:
The basic form is to create formula(s) that initialize the variables, formula(s) that set the variables, and then formula(s) that output (or otherwise use) the variables, and (of course) put the formulas in the appropriate sections.

 If the variables are for the whole report, you'd normally initialize them in the report header.  If they're some kind of group total, you'd probably use the group header.

WhilePrintingRecords;
NumberVar var1;
var1 := 0;
""

 The "" at the end is so that the formula does not produce any output on the report, so you don't have to suppress that field.  If you're putting the formula in a suppressed section (eg. a suppressed report header section), then it doesn't matter.


 Set the variable in the appropriate section:

WhilePrintingRecords;
NumberVar var1;
// Say we're accumulating a total
var1 := var1 + {some field};
""


 Output the variable in the appropriate section:

WhilePrintingRecords;
NumberVar var1;

var1


 Or, say you wanted to suppress a field/section if the variable was 3:

WhilePrintingRecords;
NumberVar var1;

var1 = 3


 If you need a bunch of different variables, you could just use separate variables, but you might want to consider using an array instead.

 James
0
 
James0628Commented:
An amendment to something early in my post:

 > If the variables are for the whole report, you'd normally initialize
 > them in the report header.  If they're some kind of group total,
 > you'd probably use the group header.

 If the variables are some kind of group total, then, yes, you'd presumably want to initialize/reset them in the group header or somewhere else in the group, but you may still want to initialize them in the report header as well.  I've had problems using global variables and I think it may have been because I didn't do things like that.  Even if you don't actually need to do it, it won't do any harm.

 James
0
 
mlmccCommented:
Unfortunately variable values set during the WHILEREADINGRECORDS pass are not saved for use later.

To get the effect you want you may have to build a subreport to run for each record to gather the information then pass it back to the main report for use in formatting.

mlmcc
0
New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

 
James0628Commented:
Thanks for the info mlmcc.  But I don't see any reason that he has to save the values specifically during the reading phase.  I know he said "while reading records", but I figured that was probably just a general term for when the report was "processing" the detail records.

 James
0
 
mlmccCommented:
I agree.  I just wanted to point that out as thereason his formulas might not be working.

mlmcc
0
 
James0628Commented:
Fair enough.  And I appreciate the info.  It might come in handy one of these days (assuming that I remember it :-).

 James
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now