Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mult-dimensional array

Status
Not open for further replies.

NavisysMatt

Programmer
Feb 21, 2000
3
0
0
US
Is there a way in RPG ILE to create a multi--dimensional array? We are using multi-occurrence data structures now, but we are looking for an alternative. Anyone's assistance would be greatly appreciated.<br>
<br>
<br>

 
I get around this problem by using numeric data:

The index to the array also happens to be data (4,0). And the items in the array are individually indexed by another set of data. Using an EVAL statement, you can then address the individual set of data in an array using something like:

Eval field = %subst(array(data1):data2:length)

You have to be careful doing this because you are limited to arrays of 16mb in size!.

 
I have done this before (several years ago), and this isn't the best solution I'm sure & involves some overhead. I simply calculated the location by using the indexes. I think I did it similar to this:

For 3 dimensions: x, y, z

Example: let's say you have 3 tables, each with 8 x 10, for a total of 240 elements. Using x,y & z as your indexes, to find the element you would compute the index as:

Eval Idx = (Xsiz * (x - 1)) + (ysiz * (y - 1))
+ (z)

Element 2, 3, 4 would be (80 * (2 - 1)) = 80
+ (10 * (3 - 1)) = 20
+ 4
= 104
Your value(s) are stored in element 104. You can easily add dimensions by changing the calculations. Remember that you are limited to 32766 elements per array. You could also compute the RRN of a record in a file, if you need more workspace.

There is a series of articles on the news/400 website (May 1998 & May 1999 if you get the printed copy) specifically about simulating multi-dimensional arrays - I'm sure those are much more sophisticated than my approach. It requires that you have a paid subscription.

Hope it helps.

Ken Hood
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top