2 Dimensional Array in RPGLE

5 pts.
Tags:
iSeries RPGLE
RPGLE array
How do I define and use a 2 dimensional array in RPGLE? 
I have to add up to 10 contracts from one file and order sequence numbers for every item on an order that belongs to a one of those contracts and then write each of those contract/sequences to it's own order. I am lost on the best way to achieve this!  Where to start, how to load, how get it into a new order.
Contracts are 5,0 and can have up to 500 sequence numbers (5,0)  
Thanks!
Biscut


Software/Hardware used:
iseries
ASKED: April 19, 2012  6:37 PM
UPDATED: May 1, 2012  7:12 PM

Answer Wiki

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

You can mimic a 2-D array in RPG by defining a multiple-occurrence data structure and then defining an array within that.
Seems overcomplicated to me.
I’d attack it by creating a (work) data file to store everything and then clear it out or delete it after the process is complete. This would be slower than a solution that keeps everything in memory, but MUCH easier to understand and maintain.

Discuss This Question: 3  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
    If arrays in RPG are difficult, code the routine in COBOL or maybe C. In COBOL, multi-dimensional arrays are made by nesting group-items at different levels and specifying an OCCURS clause. In RPG, you use a DS instead of a group-item and specify a DIM() keyword. For example:
    d ara1            ds                  dim( 99 ) qualified
    d   ara2                        10a   dim( 99 )
    d   ara3                        10i 0 dim( 99 )
    
    ara1(x).ara2(y) = 'New value' ;
    ara1(x).ara3(y) += 1 ;
    
    The example shows ara2 and ara3 both with 99 elements within ara1 that has 99 occurrences. By using LIKEDS() on the subfields, much more detail can be added at the lowest level. A third level could be added to give 3-D arrays for example. As you describe it, you might have code like this:
    d ConSeq          ds                  dim( 10 ) qualified
    d   Contract                     5p 0
    d   SeqNbr                       5p 0 dim( 500 )
    
    In this case, you have a ConSeq structure that has 10 occurrences. Each occurrence will have a Contract along with up to 500 SeqNbrs. You might want to have an additional subfield for a counter to keep track of how many of the SeqNbrs are actuallu used for this contract/sequence number group. Actually, there are multiple possibilities. For example, instead of a DIM() on the DS, you might use an OCCURS(10) keyword. And there are other ways to combine items with DIM(), too. It's hard to know what might be most useful without knowing what is going to e processed and how it's all going to be used. Tom
    125,585 pointsBadges:
    report
  • SirEvil
    Hi Tom,

    If we make 2 d arrays using qualified ds, then we can't search any element using %lookup.
    So, how to make a 2d array so that %lookup works??
    10 pointsBadges:
    report
  • TomLiotta
    Without an example, I don't know what you mean by "search any element using %lookup". Generally, you don't do lookups on multi-dimensional arrays. But if you're asking about a kind of alternating array, then yes, you can do lookups on them. . Show your array definition and describe what is in it. Then describe how you need to search through it. . 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