Solved

crystal xi: Incompletely populating a shared array via a subreport

Posted on 2014-12-12
9
443 Views
Last Modified: 2014-12-15
Hello,

I am populating an array in a subreport and using it in the main report. The array is created by reading a local excel spreadsheet with one column consisting of Dates. No matter what I try, if I shrink the subreport (I don't want it visible) the array is incompletely populated. (If I suppress it, it doesn't work at all),

In the subreport,  which is located in the report header, I have an Init formula field  in the reports header and a 'create' formula field in the details section
//INIT
shared datevar array holidaydates;
local numbervar knt := count({Holidays_.DatesOnly});
redim holidaydates[knt];
//just so we don't return an array and cause an error
local numbervar i;
for i := 1 to knt do 
    holidaydates[i] := cdate(#01-01-1970#);

//CREATE in details section
whileprintingrecords;
shared datevar array holidaydates;
holidaydates[recordnumber] := cdate({Holidays_.DatesOnly});

Open in new window


THe knt variable is correct. It's just that if I don't totally display every record in the subreport, (check can grow) The array is not totally populated.

MUST I completely display the subreport for this to work?
0
Comment
Question by:OutOnALimbAlways
  • 4
  • 3
  • 2
9 Comments
 
LVL 100

Accepted Solution

by:
mlmcc earned 480 total points
ID: 40497010
In my experience the answer seems to be yes.

Try this to get around the issue

CHange your formulas as shown

//INIT
shared datevar array holidaydates;
local numbervar knt := count({Holidays_.DatesOnly});
redim holidaydates[knt];
//just so we don't return an array and cause an error
local numbervar i;
for i := 1 to knt do 
    holidaydates[i] := cdate(#01-01-1970#);
''

//CREATE in details section
whileprintingrecords;
shared datevar array holidaydates;
holidaydates[recordnumber] := cdate({Holidays_.DatesOnly});
''

Open in new window


Format the sections of the subreport to SUPRESS BLANK SECTION
Right click the section in the left margin
CLick SECTION EXPERT
Click SUPPRESS BLANK SECTION


Format the subreport to SUPPRESS IF BLANK
Right click the subreport
CLick FORMAT SUBREPORT
CLick the last tab
Click SUPPRESS BLANK SUBREPORT

If the subreport is in its own section you can also suppress the section if blank
Right click the section in the left margin
Click SECTION EXPERT
Click SUPPRESS BLANK SECTION

mlmcc
0
 

Author Comment

by:OutOnALimbAlways
ID: 40497106
Thanks mlmcc, that did the job.  I also formatted the detail section of the subreport to print multiple columns and played around with the layout. I guess as long as you can hide the subreport, it's not really a problem, though it does kind of go against the grain to have a "if it ain't shown, it ain't there" kind of situation.
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 40497566
If you want the subreport to show something just put a field or text in the report header.  By not having anything show in the details and suppressing it when blank the subreport won't grow very much

mlmcc
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 34

Assisted Solution

by:James0628
James0628 earned 20 total points
ID: 40497812
Interesting.  I didn't realize that subreports did that.  I just tried one with a formula that incremented a count for each record.  I suppressed everything but the detail section, and unchecked "Can Grow".  When the subreport was long enough to display all of the records, I got the correct count in the main report.  When the subreport was too short, I got the last displayed count, plus 1, in the main report.  It seems that the subreport reads and "processes" all of the records that will fit, then it reads the next record, prepares the detail section (including evaluating any formulas in the section), but then sees that there's no room for the detail section, so it just quits.  Good to know.

 James
0
 

Author Comment

by:OutOnALimbAlways
ID: 40497910
I swear 75% of programming is learning the undocumented peculiarities in whatever programming language you are using!
0
 

Author Closing Comment

by:OutOnALimbAlways
ID: 40498307
It looks like this is a 'peculiarity' in crystal.  As James says, it is something to keep in mind. I should have mentioned earlier that if you try to simply use an excel spreadsheet in your main report along with another database, it won't work. Crystal warns you that more than one database driver is not supported, and in my case, attempting to use both sql server and excel in one report really screwed up the results.
0
 
LVL 34

Expert Comment

by:James0628
ID: 40498377
FWIW, more than one kind of db in a report can work.  It's not fully supported, so some specific features don't work, but it can be done.  Of course it's best to avoid it if possible.  And if you're not just reading the data sequentially, Excel files can be really slow, since they're not indexed, etc.  FWIW, I got around that by having stored procedures read the Excel data into indexed temp tables, or table variables, and then joining those tables to the other tables.  Multiple users were also a problem with Excel files, so I only used them with some specific reports that were only run occasionally, by a few specific people.

 James
0
 

Author Comment

by:OutOnALimbAlways
ID: 40500850
James, Ty for the extra tips about excel in crystal.
0
 
LVL 34

Expert Comment

by:James0628
ID: 40500914
No problem.

 James
0

Featured Post

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question