Emaborsa
Emaborsa

Reputation: 2850

Crystal Reports: Create Array or get values from a column

Say I'm working on a report, on a column called someTable.someColumn. What I need is to have all of the values in the ReportHeader. I know I cound create a subreport, pass them this column and iterate it in the details, but I would like to know if it's possible to do it without a subreport.

If I use the following, I get the right result, which in my case is 9:

COUNT(someTable.someColumn)

I also tried the following, but it doesn't work - it only takes one of the 9 values randomly.

Local NumberVar i := 0;
Local StringVar Array items := {someTable.someColumn};
Local StringVar output := "";
while (i < count(items)) do (
  i := i+1;
  output := output + items[i];
);

output;

Is it possible to iterate over a column in order to get the values?

Upvotes: 2

Views: 19501

Answers (3)

Paul White
Paul White

Reputation: 1

Reason why you cannot use a subreport?

My reports have a front page with audit controls and the selection criteria. I pasted a subreport in the header section - easy to implement using the previously suggested code:

formula MyVar
global StringVar output; output := output + {MyTable.MyColumn} + ",";

Painted @Myvar field into footer section. Suppress all other sections. Resize the subreport so it fits on one line and move it under the other selection parameters in the header section.

Upvotes: 0

Hannele
Hannele

Reputation: 9666

I haven't found a way to do this in the report header, but you could put it in your report footer with the following formula:

global StringVar output;
output := output + {someTable.someColumn} + ",";

This will execute each time someTable.someColumn changes over the course of report generation, and append it to the global variable. Unfortunately, it doesn't keep all instances of it up to date - for example, if you include it in the report details somewhere, you'll be able to see the evolution of output over the course of the report. In the header, it'll only display the first value.

Note: You won't want to set output := "" in this formula, as that'll reset the value each time. It seems, though, that Crystal automatically initializes the variable for you when it's created, and I didn't run into any errors with only the above formula (i.e, I didn't need to create a second formula to initialize output). I've also included a delimeter (+ ","), to help separate each of the values, but you can easily just remove that.

Upvotes: 0

Lee Tickett
Lee Tickett

Reputation: 6027

You can't do this in the report header. You have to use the detail section to read each value.

The only solution which springs to mind is using a subreport. Although you wouldn't pass them this column and iterate it in the details. Because it would only pass the first value from the column. You would pass it the report parameters which it could use to obtain the column values from the database the same way your main report does.

Upvotes: 2

Related Questions