on 06-21-2012 10:44 AM
Within the details section I have a field "Country of origin" so this varies per item. I am trying to acheive a fiel ideally in the header (but could be a footer) which displays this information together in a line.
Eg -
Details A - field = UK
Details B - field = US
Details C - field = China
Details D - field = UK
The header or footer field would show - UK, US, China
Please note UK only appears once even though it is in both detail A and D.
Really struggling to get this to work so any help would be greatly appreciated?
Thanks.
Hi Alan,
Here's what you need to do:
1) Create this formula and place it on the Details Section:
WhilePrintingRecords;
stringvar array arr;
numbervar i;
if not({Customer.Country} in arr) then
(
i := i + 1;
redim preserve arr[i];
arr[i] := {Customer.Country};
);
arr[i]
You may choose to suppress this formula
2) Create another formula to display the concatenated string. Place this formula on the footer:
WhilePrintingRecords;
stringvar array arr;
stringvar fin;
numbervar j;
for j := 1 to ubound(arr) do
fin := fin + arr[j] + ", ";
left(fin,len(fin)-2);
Let me know how this goes!
-Abhilash
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Alan,
This will NOT work in the Page Header because the values are accumulated in the Details Section.
You can, however, show these values in the Page Header by using a Subreport. But that would mean running the same query twice (hitting the database twice).
All you need to do is add the same report as a subreport and place it in the Report Header.
Change the variable in the 2nd formula to a shared variable:
WhilePrintingRecords;
stringvar array arr;
shared stringvar fin;
.
.
.
...and the rest of the code is the same;
Then create a new formula in the Main Report to access the shared variable:
shared stringvar fin;
Place this formula in the Page Header and you should see that the variable returns all the values.
-Abhilash
Hi Abhilash: I tried this method and it builds the array fine I presume. But the array accumulates across each group when I need it to clear out with each group. If I put a redim statement in a group header section. I get an array error. If I do not use redim in the group header the array builds and builds across all groups. If not the array building across all groups the stringvar "fin" is not clearing out with each group so I get a footer with
abcd, defg, ikjl, for first group (great it works)
for group2 I get abcd, defg, ijkl, abcd, pqrst,
then group 3
abcd, defg, ijkl, abcd, pqrst, trsu, xyz
WhilePrintingRecords;
stringvar array arr;
numbervar i;
if not({Customer.Country} in arr) then
(
i := i + 1;
redim preserve arr[i];
arr[i] := {Customer.Country};
);
arr[i]
You may choose to suppress this formula
2) Create another formula to display the concatenated string. Place this formula on the footer:
WhilePrintingRecords;
stringvar array arr;
stringvar fin;
numbervar j;
for j := 1 to ubound(arr) do
fin := fin + arr[j] + ", ";
left(fin,len(fin)-2);
Can this be told to reset on the change of a field. I need the concatenation to be grouped on a particular field or two.
Thank you,
Bobby
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think, reseting stringvar fin won't help. This is a mystery why a variable displaying the array value does not get reseted. Even an attempt to reset the array itself fails. I worked on this but couldn't get it right.A forum post by my respected senior colleague Jamie Wiseman on "reseting dynamic array" also does not seem to work in this case(may be I am wrong).
If someone can share their thoughts that would be great.
A working alternative is to create a manual running total instead of an array.
Here's how:
1.Create 'Collect Values' formula and place it in 'Details' section:
Whileprintingrecords;
stringvar getCountryOforigin:= getCountryOfOrigin + {table.CountryOfOrigin} + ','
2. Create 'Show Values' formula and place it in 'Group Footer' section:
Whileprintingrecords;
stringvar getCountryOforigin;
3.Create 'Reset Value' formula and place it in 'Group Header' section:
Whileprintingrecords;
stringvar getCountryOforigin:=''
Note:
1.It is possible to show the comma-separated values in Group Header also.
Just place a sub report in Group Header(of main report) and link on
CountryOforigin field and 'Hide' all sections of sub report except Group Footer.
2. Using long strings in Crystal Reports is always an issue because of the limit on length of string that a variable can hold.
But this can always be checked and multiple string variables can be assigned.
For that matter, same is the case with array size that has max limit of 1000 elements.
Thanks,
Prathamesh
This is just example code, but I hope it helps you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.