Solved

crystal xi: Incompletely populating a shared array via a subreport

Posted on 2014-12-12
9
441 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
 
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
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 …
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now