How to define two dimensional arrays in RPGILE

260 pts.
Tags:
2D arrays
AS/400
RPG
RPG ILE
RPGILE
I need to create an array that contains a code (2,0) and hrs worked (5,2) for that code. something like 01 2.3 4.3 5.6 7.0 8.0 02 5.0 6.0 7.0 7.0 6.5 I will then take this array and load a subfile to display on a screen. Thanks, John

Answer Wiki

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

I assume you have finite limits for these arrays – that is, for each code entry, there is a fixed (or maximum) number of hours worked entries?

Usually, I would do this as two arrays – the first would be code (say, 50 entries), and the second hours worked.

If there are never more than 10 hours worked entries for any code, then the hours worked array will be 10 * 50 entries.

Entries 1 to 10 will be reserved for the code value in the code array element 1.
Entries 11 to 20 will be reserved for the code value in the code array element 2…

…and so on.

You can see that for any code entry you can use arithmetic to get the start element number for the matching list of elements in the hours worked array.

You can ‘hide’ the code you write to manipulate the arrays, by using procedures to write to and read from the arrays. Then in the body of your code you can use the procedure calls and pass parameters to identify what you want to write and what you want to read.

This is a very simple, even crude, way of looking at your problem, but for most purposes it will work. If your requirements are more sophisticated, please describe them more fully and I’ll come back with some refinements!

Regards,

Sloopy

==========================================================

The easiest way for your case is probably something like this:<pre>
D aHrs ds dim( 2 ) qualified
d Code 2
d HrsWorked 3p 1 dim( 5 )</pre>
Tom

Discuss This Question:  

 
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

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