I am loading a DS from a database file into an array nine length with three elements, i.e. 100101102. I want to increment the array to load each element one at a time and save it to a standalone variable ( 3 bytes long). In another forum, someone said the receiver must be a %subarr variable. In any case, this code gives an error of (Array has too many omitted indexes).
Below is my code example:
Fmaster if e k disk
Dx s 3u 0
Dy s 3u 0
Ditmtype s 3a
Darr1 s 9 dim(1000)
Dtypes ds
D type1 3a
D type2 3a
D type3 3a
/free
x = 1;
read master;
dow NOT %eof(master) and x <= 600;
arr1 = types;
dow x <= 3;
itmtype = %subarr(arr1:x:3);
x = x + 1;
enddo;
read master;
enddo;
*inlr = *on;
/end-free
The array gets loaded, just as I want but picking out the individual elements from the array gives me the compilation error.
Software/Hardware used:
iSeries;V5R4;RPG Free
ASKED:
November 30, 2010 3:28 PM
UPDATED:
December 7, 2010 8:30 PM
The array gets loaded, just as I want …
If that’s true, I’m not clear on what you want. This line of code”:
…should load TYPES into 1000 elements of ARR1. Can you explain why that is “just as you want”?
Then:
ITMTYPE gets three elements of ARR1 assigned to it. Because it is in a loop that cycles X from 1 to 3, the first time through elements 1, 2 and 3 are assigned to ITMTYPE. The second time through, elements 2, 3 and 4 are assigned to ITMTYPE. Finally, elements 3, 4 and 5 are assigned to ITMTYPE.
ITMTYPE is only 3-bytes long, so the practical result is that it only ends up with element 1 the first time, 2 the second time and 3 the third time. But why load three elements at a time with %SUBARR() when ITMTYPE is only big enough to hold one? This would probably be better:
itmtype = arr1( x );And why have ARR1 as DIM(1000) when you never use more than three at a time?
Perhaps you could describe what you need to do. We can describe how to use the functions to fit what you need.
Tom
Very confused.
%SUBARR is used when you have a command to work with an array and you want to apply it to a part of the array .. like the %lookup function.
You want a part of a string that happens to be an array .. part of a string is %subst
so this might be
itmtype = %subst(arr1(x):1:3);
which would extract the first three characters from arr1(x)
Phil
I reviewed what I posted and saw that I hadn’t finished it. I added the artypes reference that I previously left out. I’m not sure how I managed to paste in an early copy of what I intended.
Tom
and since you want the first three characters to be placed in a 3 character field
as Tom said that can be done with
itmtype = arr1(x);
which attemps to move the characters in the array member in a left justified format to the field itmtype and results in truncation so just the first 3 characters are there.
Phil
Thanks for all your input.
Tom and Philip1jb were accurate in that I didn’t need to even be using %subarr. I tossed the original logic (that’s kind of the way) I used to do it in RPG/400. I wrapped an array 3 elements, 3 long around the data area name.
1. It reduced the code and confusion 90%.
2. It worked flawlessly for what I needed. I think I will incorporate DS and arrays more often now.
Again, thanks.
I think I will incorporate DS and arrays more often now.
Data definitions can be more important than program instructions. Appropriate definitions can significantly reduce coding.
Tom