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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multi-dimensional array

Status
Not open for further replies.

NavisysMatt

Programmer
Feb 21, 2000
3
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 appreciate your response. I am trying to create a common edit module for several different versions of a file(s) so I can not be bound by the DDS. I am currently pursuing parsing the file out into a multi-occurrence datastructure(file, field, value, data type, length, and decimal positions)I am reluctant to settle for this approach and would like to use a multi-dimensional array. I have heard of it being done, but can not find it in any books. Do you know how to create a multi-dimensional array in RPG ILE?
 
Navisysmatt;

Multi-dimensional arrays is one thing that RPG in most versions does NOT have. However, we've become used to accomplishing it by using two arrays.

The first array represents the first dimension. Lets say thats 64 elements of 32 bytes. The array would be defined as 64 x 32. And, lets say each 32 byte element is divided into 4 elements of 8 bytes each. This array would be defined as 4 x 8. Next, define a data structure of 32 bytes. Be sure your also define the second dimension array over this same space.

When loading, referencing, retrieving the array:

With the desired first dimension array value (occurance) move the element to the 32 byte data structure. Then reference the second dimension element number from the second array.

Sounds more difficult that it is but it works just fine. The ONLY limitation is that you are limited to 9999 elements. But, anything that large would warrant a file anyway.
 
In RPG IV its not difficult. I think you can do the same thing in earlier versions of RPG.


D MyArray DS OCCURS(50)
D MyField1 5
D MyField2 6 0
D MyField3 10


C 5 OCCUR MyArray
C EVAL WorkField = WorkField + MyField3
In the C Spec you will now see the fith occurance
of the MyArray datastructure and can reference MyField1, MyField2 and Myfield3 as normal.


Regards

Roy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top