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
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:
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:
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
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??
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