
Question:
This is for Crystal Reports 2013 Support Pack 1
I have a Shared Variable that's giving me fits. In particular, it works while my report is only one page long, but it resets itself if the report is more than a page long and I don't know why. The end result is that it displays only the data for the page it is on, not the data for the grouping it lives in, which is the intended behavior.
Here's what I have:
In a formula called InitTicketList
, it is "declared" like this:
WhilePrintingRecords;
Global StringVar TicketList := "";
This formula field is on the report in Group Header #2a
.
Formula UpdateTicketList
is declared like this:
WhilePrintingRecords;
Global StringVar TicketList;
StringVar item := Split({Command.TicketNumber}, ".")[UBound (Split({Command.TicketNumber}, "."))];
if InStrRev(TicketList, item) <= 0 then
TicketList := TicketList +item + "; ";
I believe the logic here is correct for two reasons: I have tested it with data and it works. What it does is append one instance of the second section of a number formatted like xxx.xxxxxxxxxxxxxxxxx into TicketList. The idea is to display a list of all those parts, displaying each part only once. Also, this report works perfectly as long as it is one page long.
UpdateTicketList
is on the report in Details e
.
Finally, ShowTicketList
looks like this:
WhilePrintingRecords;
Global StringVar TicketList;
and it is on the report in Group Footer #2b
.
There is also a ClearTicketList
formula, also in Group Footer #2b
. It looks like this:
WhilePrintingRecords;
Global StringVar TicketList :="";
However, I have removed ClearTicketList
as an experiment and the report behavior was still the same.
I'm looking for something or someone that can explain this behavior to me. I don't know if I understand Crystal Report's 3-phase report engine well enough to reason this out. I'm unfortunate in that I maintain Crystal Reports I didn't write and my Crystal-Fu is not very deep.
My goal is to have this formula work for a report of any number of pages and any number of groupings.
UPDATE:
While it appeared as if the global variable resets after each page, that is not the whole story. The detail section was suppressed, making it hard to see what happens. It was actually resetting after each detail record that have a blank value in {Command.TicketNumber} and this happened to coincide with a new page. Of course this threw off the UpdateTicketList
formula a bit. I modified it to:
WhilePrintingRecords;
Global StringVar TicketList;
StringVar item := Split({Command.TicketNumber}, ".")[UBound (Split({Command.TicketNumber}, "."))];
if InStrRev(TicketList, item) <= 0 then
TicketList := TicketList +item + "; "
else
TicketList := TicketList
Now it truly only resets once per page.
Answer1:In all formulas where the variables are reset there has to be adequate checks in place to makes sure the resetting only happens on first record and not for example on every page, like this:
If OnFirstRecord Then Global StringVar TicketList := "";
Other functions that might be possible for different checkings are for example:<br />GroupNumber
<br />Next
<br />Previous
<br />RecordNumber