Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

multi-dimensional arrays in ILE RPG

1,781 views
Skip to first unread message

Paul Newport

unread,
Feb 13, 1997, 3:00:00 AM2/13/97
to

Does ILE RPG support multi-dimensional arrays (eg FRED(10)(45)(456) would
define a 10 by 45 by 456 3d array) and if so how ho you code for them ?

It's easy enough in C,PL/1 or REXX. Has RPG entered the seventies yet ?


Paul Newport

On the information super B road


William A. Erhardt

unread,
Feb 13, 1997, 3:00:00 AM2/13/97
to

RPG does not support multidimensional arrays, at least not directly. The
closeest you get is an occurs data structure. I've used this approach many
times. Define an array to store index values. Each element in the array
would contain the index value with the array element value used to retreive
the occurance. I'll try to demonstrate, understand that this code is
written frehand.

DARRARY S 5 0 DIM(XXX)
DOccurs DS OCCUR(XXX)
D field1 1 5
Dfield2 6 10

C Z-add 1 x
5 0
C value lokup array,x
01 (equal test)
C if *in01 = *off
C z-add 1 x
C *blanks lokup array,x
01
C if *in01 = *on
c move value array,x
c endif
c endif
c x occur occurs
c move values


I hope this helps.

The TEAMIBM Network

unread,
Feb 14, 1997, 3:00:00 AM2/14/97
to

Since you've already had advice on how to "fake" the arrays, I'll just
point out that if you are at V3R2 or later, you can wrapper the code
in a procedure so that at least in the main logic it appears to be
a regular multi-dim array.


Jon Paris - jo...@vnet.ibm.com - AS/400 AD

Dave Mahadevan

unread,
Feb 18, 1997, 3:00:00 AM2/18/97
to

Good idea. Now how do we dynamically allocate the array? Has IBM come
up with a *VARSIZE (now available for character variables) for
dimensioning arrrays, structures?

--
Thank You.

Regards

Dave Mahadevan.. mailto:maha...@fuse.net

Gary Guthrie

unread,
Feb 19, 1997, 3:00:00 AM2/19/97
to maha...@fuse.net

>Good idea. Now how do we dynamically allocate the array? Has IBM come
>up with a *VARSIZE (now available for character variables) for
>dimensioning arrrays, structures?

With V3R7 RPG contains opcodes to allocate, reallocate and deallocate
storage. This in conjunction with pointers and based data structures
will allow you to dynamically size arrays.

Watch for an upcoming article in News/400 magazine where Julian
Monypenny describes this technique and provides code to show you how
it's done.

Gary Guthrie

The TEAMIBM Network

unread,
Feb 19, 1997, 3:00:00 AM2/19/97
to

>>Good idea. Now how do we dynamically allocate the array? Has IBM
>>come up with a *VARSIZE (now available for character variables) for
>>dimensioning arrrays, structures?

Not exactly - although it's on the shopping list for future releases.

I use prototyped versions of malloc, realloc, and free to dynamically
allocate memory to a BASED array or MODS. You do have to keep control
of your maximum number of entries, but then I prefer to do that than
have RPG do it for me anyway.

I've also used the C sort and search functions against such structures
which works well.

You can also use the ILE dynamic memory APIs, User Spaces (great if
you want to allow an array to be shared between users)
or there's also direct RPG Opcode suppoet in V3R7 (ALLOC, etc.)

Paul Newport

unread,
Mar 10, 1997, 3:00:00 AM3/10/97
to

pa...@tropwen.demon.co.uk (Paul Newport) wrote:

>Does ILE RPG support multi-dimensional arrays (eg FRED(10)(45)(456) would
>define a 10 by 45 by 456 3d array) and if so how ho you code for them ?

>It's easy enough in C,PL/1 or REXX. Has RPG entered the seventies yet ?

Ta for all the advice, I guess NO is the answer ;-)

0 new messages