RPG Free Array Processing

5 pts.
Tags:
IBM iSeries
iseries v5r4
RPG arrays
RPG ILE
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

Answer Wiki

Thanks. We'll let you know when a new response is added.

Maybe this is what you are trying for:<pre>
dow NOT %eof(master) and x <= 600;
%subarr(arr1:x:3) = artypes;
x += 3;
read master;
enddo;</pre>
Those changes are all inside of your original DOW loop.

The D-specs need this change:<pre>
Dtypes ds
D type1 3a
D type2 3a
D type3 3a
D artypes 3a dim(3) overlay( types )</pre>
By including an array definition overlaying the DS, the %SUBARR() becomes available. The function copies an array (or portion of an array) to a portion of another array (or to an array). IOW, it needs an array reference on both sides of the equation.

Tom

Discuss This Question: 6  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • TomLiotta
    The array gets loaded, just as I want ... If that's true, I'm not clear on what you want. This line of code":
    arr1 = types;
    ...should load TYPES into 1000 elements of ARR1. Can you explain why that is "just as you want"? Then:
    itmtype = %subarr(arr1:x:3);  
    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
    125,585 pointsBadges:
    report
  • philpl1jb
    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
    49,930 pointsBadges:
    report
  • TomLiotta
    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
    125,585 pointsBadges:
    report
  • philpl1jb
    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
    49,930 pointsBadges:
    report
  • SKF
    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.
    75 pointsBadges:
    report
  • TomLiotta
    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
    125,585 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following