title: Crystal Reports: Shared variable resets after page instead of group
body: <p>This is for Crystal Reports 2013 Support Pack 1</p>
  
  <p>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.</p>
  
  <p>Here's what I have:</p>
  
  <p>In a formula called <code>InitTicketList</code>, it is "declared" like this:</p>
  
  <pre><code>WhilePrintingRecords;
  Global StringVar TicketList := "";
  </code></pre>
  
  <p>This formula field is on the report in <code>Group Header #2a</code>.</p>
  
  <p>Formula <code>UpdateTicketList</code> is declared like this:</p>
  
  <pre><code>WhilePrintingRecords;
  Global StringVar TicketList;
  StringVar item := Split({Command.TicketNumber}, ".")[UBound (Split({Command.TicketNumber}, "."))];
  if InStrRev(TicketList, item) &lt;= 0 then
      TicketList := TicketList +item + "; ";
  </code></pre>
  
  <p>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.</p>
  
  <p><code>UpdateTicketList</code> is on the report in <code>Details e</code>.</p>
  
  <p>Finally, <code>ShowTicketList</code> looks like this:</p>
  
  <pre><code>WhilePrintingRecords;
  Global StringVar TicketList;
  </code></pre>
  
  <p>and it is on the report in <code>Group Footer #2b</code>.</p>
  
  <p>There is also a <code>ClearTicketList</code> formula, also in <code>Group Footer #2b</code>. It looks like this:</p>
  
  <pre><code>WhilePrintingRecords;
  Global StringVar TicketList :="";
  </code></pre>
  
  <p>However, I have removed <code>ClearTicketList</code> as an experiment and the report behavior was still the same.</p>
  
  <p>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.</p>
  
  <p>My goal is to have this formula work for a report of any number of pages and any number of groupings.</p>
  
  <p>UPDATE:</p>
  
  <p>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 <code>UpdateTicketList</code> formula a bit. I modified it to:</p>
  
  <pre><code>WhilePrintingRecords;
  Global StringVar TicketList;
  StringVar item := Split({Command.TicketNumber}, ".")[UBound (Split({Command.TicketNumber}, "."))];
  if InStrRev(TicketList, item) &lt;= 0 then
      TicketList := TicketList +item + "; "
  else 
      TicketList := TicketList
  </code></pre>
  
  <p>Now it truly only resets once per page.</p>