Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Technical Questions
Message Icon Topic: Where to create an array? Post Reply Post New Topic
Author Message
bshort1023
Newbie
Newbie
Avatar

Joined: 18 Jan 2012
Location: United States
Online Status: Offline
Posts: 18
Quote bshort1023 Replybullet Topic: Where to create an array?
    Posted: 18 Jan 2012 at 2:12am
I need to loop through the detail records to create an array. I have seen 100 examples of the code used to create the array (including the examples from the Crystal Reports Encyclopedia) but none of them show where to place the code. Is it in the formula editor?

Thanks,

bshort1023
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 18 Jan 2012 at 3:15am
yes, you would create the array in a formula.  If you need to reuse it, make is shared or a global array, like:
shared numbervar array aTest;
 
What are you going to do with the array, as I haven't used them much?
IP IP Logged
bshort1023
Newbie
Newbie
Avatar

Joined: 18 Jan 2012
Location: United States
Online Status: Offline
Posts: 18
Quote bshort1023 Replybullet Posted: 18 Jan 2012 at 5:30am
For each line on a sales order there are multiple (up to 50) detail records about that line item.  So instead of having one record with all of the information in separate fields, the information for one line on the sales order is stored in many separate records.  This makes it a nightmare for reporting.  What I would like to do is loop through the detail records and place the information I need into an array.  Then I will hide the actual detail records and show the fields from the array.
 
Here is what I put in the formula field:

stringvar array aTest;
aTest := MakeArray ("Hi", "Bye");
Redim Preserve aTest[2];
 
When I check the syntax or try to save I get a message that the result of a formula cannot be an array.
 
Thanks for your help.
 
Bill
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 18 Jan 2012 at 6:47am
If I read the Help file correctly, you don't need th redim preserve line, as that will just do what the MakeArray is doing.
 
The characteristic of arrays that make them less than useful in Cr is that they are only 1 dimesional...so a group of fields to track requires as many arrays as you have fields + 1 (probably to have a lookup).
 
If the reporting is such a nightmare, you might want to try a stored proc.
 
HTH
IP IP Logged
bshort1023
Newbie
Newbie
Avatar

Joined: 18 Jan 2012
Location: United States
Online Status: Offline
Posts: 18
Quote bshort1023 Replybullet Posted: 18 Jan 2012 at 7:25am
I was thinking more along the lines of one array for each line on the sales order.  Row one in each array would hold the same data, for example line one on the sales order would store Voltage in TestArray1[1].  For line 2 on the sales order Voltage would be stored TestArray2[1], etc...
 
Not familiar with stored procedures (Is that SQL?).
 
Any idea why I would be getting the error about saving an array in a formula?
 
Thanks again.
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 18 Jan 2012 at 1:05pm
so you have tried:
stringvar array aTest;
aTest := MakeArray ("Hi", "Bye");
 
If that is not working, I am not sure as that is what Cr help has
 
Yes, stored procs are SQL...I think of them as batch files for SQL...a series of SQL commands.  In addtion, you can create temp tables in a stored proc, which allows for massive flexibility in how you process your data.
 
Typically, I create 'super' rows of data, which in the case of an invoice might be invoice header and a detail line combined in one line.  Or you can return multiple tables and link them in CR...but the bottom line is that you can create a datatable(s) that contains only the information that is needed for the report without additional columns...or with columns that do not exist in the database just for report processing. 
 
Given this, OK, all my reports are written with stored procs as the method that the report gets its data, and after you've done a few, they are really easy to code.
 
In essence what you do is take all the work that CR needs to do to get the data, off of the application server and place it on the database server which tends to be a more powerful machine and then leave the display of the report to CR.
 
HTH
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.031 seconds.