Multi Dimension Array / ALT
Last Post 15 May 2004 12:38 PM by Peter Myers. 12 Replies.
AddThis - Bookmarking and Sharing Button Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages Not Resolved
Anonymous
Editorial Staff Member
Editorial Staff Member
Posts:81236

--
27 Apr 2004 07:32 PM
Hi, I would like to check with RPG ILE, can i use multi-dimensional array? i know from compile-time array, i can use ALT, but for pre-run time array, i can't use ALT, even i remove CTDATA and PERRCD, i still can't use, and if i don't want to use fromfile(filename) in my array definition, what other methods can i use?
Scott Klement
Editorial Staff Member
Editorial Staff Member
Posts:16345
Avatar

--
27 Apr 2004 11:04 PM Accepted Answer
In V5R2 you can have sort-of have multidimensional arrays because you can make an array of data structures, and a data structure can store another array. For example: D myArr ds qualified dim(100) D dim2 10A dim(100) D x s 10I 0 D y s 10I 0 c eval x = 4 c eval y = 5 c eval myArr(x).dim2(y) = 'something' You can simulate a multi-dimension array in earlier releases by declaring an array large enough to support all possible elements. For example, if you wanted a 2-dimensional array with 100 elements in the first dimension, and 100 in the second, you'd need to declare a 10000 element array (because 100 * 100 = 10000). Then use multiplication to calculate which element you want to use. For example: d myArr s 10A dim(10000) D x s 10I 0 D y s 10I 0 D elem s 10I 0 c eval x = 4 c eval y = 5 c eval elem = ((x - 1) * 100) + y c e
Sunil
New Member
New Member
Posts:15
Avatar

--
28 Apr 2004 01:41 AM Accepted Answer
Hi Scott, Can you please tell me what the key word QUALIFIED does? I have never been to completely understand this keyword. Thanks, Sunil
Anonymous
Editorial Staff Member
Editorial Staff Member
Posts:81236

--
28 Apr 2004 03:31 AM Accepted Answer
Because i normally use ALT for 2 dimension array (compile time) which have to hard code 2 sets of array on the bottom of the source code. for example, DD Demand Draft CO Cashier Order TT Tele Transfer etc. but when i try to use that on pre-run time, i can't compile my program. the Red book said remove the CTDATA and PERRCD, but i still can't compile after removed them. The red book title is "WebSphere® Development ILE RPG Reference", SC09-2508-03 Further to explore to this topic, can i lookup this multi dimension array? should i use TLookup? or normal Lookup? Regards, John
Anonymous
Editorial Staff Member
Editorial Staff Member
Posts:81236

--
28 Apr 2004 09:47 AM Accepted Answer
ALT does not produce a two dimensional array, which is an array with 2 subscripts: (x,y). You can simulate multidimensional arrays with a single dimensional array and arrithmetic, but I do not think that is what you want. ALT produces a one dimensional array with 2 fields. You can still have ALT arrays in RPGIV just fine. Or you can load the arrays separately, and then just use the same subscript you looked up on one to get the value in the other. When you use ALT, the values for the two arrays are stored together at the bottom of the program, not in separate entries. Exact arrangement depends on the keywords perrcd. If you try to load two arrays when you used ALT, you would have gotten an error, since it was expecting one combined array. This is old stuff; its been this way since the SYS38. AAA111 BBB222 rather then AAA BBB ** 111 222 Another method to get arrays with multiple fields is as follows: ddsMyArray ds d ARR1 dim(100) d a_1 overlay(ARR1:*NEXT) d a_2 overlay(arr1;*NEXT) d a_3 overlay(arr1:*NEXT) But I haven't tried this with compile time data. This exact notation may need V5R2, but minor variations have existed for a while.
Barbara Morris
Senior Member
Senior Member
Posts:5201

--
28 Apr 2004 01:51 PM Accepted Answer
John, I don't think you really mean "pre-run time array". A pre-run time array is one that uses FROMFILE, but you said you don't want to use FROMFILE. I think what you want is a "run time array"; a run time array is an ordinary array that doesn't have CTDATA or FROMFILE. To have two associated runtime arrays, you use overlay arrays as Lynne suggested. With overlay arrays, if you do a SORTA on one of the overlay arrays, the other overlay arrays will get sorted along with it.
D arrayDs           ds
D info dim(3)
D code 2a overlay(info:*next)
D descr 20a overlay(info:*next)

// code and descr are both 10 element arrays

// set some values
code(1) = 'DD';
descr(1) = Demand Draft';

code(2) = 'CO';
descr(2) = 'Cashier Order';

code(3) = 'TT';
descr(3) = 'Tele Transfer';

for i = 1 to 3;
dsply code(i) ' ' descr(i);
endfor;

// displays
// DSPLY DD Demand Draft
// DSPLY CO Cashier Order
// DSPLY TT Tele Transfer

i = lookup('TT' : descr); // oops, should be %lookup
dsply ('TT elem is' + %char(i));
dsply code(i) ' ' descr(i);

// displays
// DSPLY TT elem is 3
// DSPLY TT Tele Transfer

sorta code;

for i = 1 to 3;
dsply code(i) ' ' descr(i);
endfor;

// now sorted, displays
// DSPLY CO Cashier Order
// DSPLY DD Demand Draft
// DSPLY TT Tele
Anonymous
Editorial Staff Member
Editorial Staff Member
Posts:81236

--
28 Apr 2004 05:29 PM Accepted Answer
What does keyword QUALIFIED do? If it's coded on a data structure definition, it means that its subfields must be referred to using "qualified" notation. That is, in the form "DS.SUBF". Note the dot separating the data structure name from the subfield name. This way, you can have the same subfield name in two or more data structures. It also allows more complex data structuring, such as array data structures (ie DS(I).SUBF) and subfield data structures (ie DS.SUBFA.SUBFB). Cheers! Hans
Anonymous
Editorial Staff Member
Editorial Staff Member
Posts:81236

--
06 May 2004 08:05 PM Accepted Answer
hi Barbara, just a short question, how do i get lookup works? currently i can't compile because lookup not defined? thanks, John Shew
Anonymous
Editorial Staff Member
Editorial Staff Member
Posts:81236

--
06 May 2004 11:22 PM Accepted Answer
> hi Barbara,
>
> just a short question, how do i
> get lookup works? currently i can't compile
> because lookup not defined?
>
> thanks, John
> Shew

i think it suppose to be %lookup
Anonymous
Editorial Staff Member
Editorial Staff Member
Posts:81236

--
07 May 2004 05:47 AM Accepted Answer
That should be "%lookup('TT':descr)", not "lookup('TT':descr)".
Anonymous
Editorial Staff Member
Editorial Staff Member
Posts:81236

--
09 May 2004 11:30 PM Accepted Answer

Peter Myers
New Member
New Member
Posts:33

--
15 May 2004 12:38 PM Accepted Answer
Dear Hans, Weren’t you confusing ie. (id est = that is, ie. elucidation) with eg. (exempli gratis, ie. exemplification) in your earlier post in this thread? Sorry, this is a pet peeve of mine, and I know it was just a slip on your part.
Anonymous
Editorial Staff Member
Editorial Staff Member
Posts:81236

--
17 May 2004 05:31 AM Accepted Answer
Well, a pet peeve of mine is people who worry too much about the "rules" of grammar and spelling! ;-) Cheers! Hans
You are not authorized to post a reply.

Acceptable Use Policy