|
A multidimensional array is not hard to use from a two dimensional array. Looking at the way arrays are stored you can very easily build a function to use a 2 dimensional array as a 3 dimentional array. (Er, maybe I mean 1 and 2 dimensional, now I'm getting confused). Say, for instance, I have an array set up as D abc DS 100 D abc1 10A if I want to look at this as a 10 x 10 array the math is easy. to get any element, such as 2 x 3 you just multiply X-1 * 10 + Y 2 - 1 * 10 = 10 + 3 = 13. So, element [2, 3] = [13] I could see building a function to return this but it would require 4 parameters, size of array X, size of array Y, occurrence X and occurance Y. This would return a single number, the element number in the 2 dimensional array. D Eval Return = (OccurX - 1) * ArrayX + OccurY Turn this into a % function and you could do stuff like: D Eval MyArray[%ConvertArray(10, 10, 2, 3)] = someval Admittedly, this is not as easy as calling MyArray[2, 3] directly. Regards, Jim Langston Peter Dow wrote: > > Hi James, > > Let's see if I can come up with an example code. > > D abc DS 10 (occurrences that is) > D abc1 10A > > D xyz DS based(ptrXYZ) > D xyz1 10A > > c 1 occur abc > c eval ptrXYZ = %addr(abc) > c 2 occur abc > > c if abc1 = xyz1 (this is comparing 2 different > occurrences) > c ... > c endif > > As I said, I haven't actually tried this, but my understanding is that after > the 2nd OCCUR stmt, the xyz data structure is still pointing to the 1st > occurrence. The %addr(abc) returns a pointer to whatever the current > occurrence is. > > As to using pointers to do multi-dimensional arrays, I think you're right it > might get pretty ugly. IBM almost slipped up and gave it to us with those > array subfields, where you can overlay an array with subfields of an array > element and then sort the array by those subfields. But they didn't allow > the subfields to be arrays. > > I haven't had much need for multi-dimensional arrays, but the couple of > times I have, they've been just 2-D arrays, which are fairly easily > simulated by calculations or an array within a multi-dimensional data > structure. > > HTH > Peter Dow > Dow Software Services, Inc. > 909 425-0194 voice > 909 425-0196 fax +--- | This is the RPG/400 Mailing List! | To submit a new message, send your mail to RPG400-L@midrange.com. | To subscribe to this list send email to RPG400-L-SUB@midrange.com. | To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com. | Questions should be directed to the list owner/operator: david@midrange.com +---
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.