|
Hello, > Nevermind, I think I found my answer. I should use an occur correct? > Kinda like this: [SNIP] Personally, I prefer to use qualified data structures instead of MODS. I find setting the occurrance with the OCCUR op-code or %occur() BIF to be awkward and clumsy. I'd much rather be able to use an index -- like you can with any other array. Here's a sample that uses a qualified DS: D Test1 ds D Cost 20 3 D Price 20 3 D Cols ds qualified D dim(6) D Value likeds(Test1) dim(5) D x s 10I 0 D y s 10I 0 /free // set all Costs to 50 & Prices to 100. for x = 1 to %elem(Cols); for y = 1 to %elem(Cols.Value); Cols(x).Value(y).Cost = 50; Cols(x).Value(y).Price = 100; endfor; endfor; // set cost(3,2) to 55 and Price(3,2) to 105 Cols(3).Value(2).Cost = 55; Cols(3).Value(2).Price = 105; /end-free That sample code requires V5R2. If you're stuck an an older release, then maybe the best solution is to simply use multiplication? It's very simple to make an single dimension array act like a multiple dimension array using multiplication. For example, if you've got 5 rows of 6 columns, you could think of that as a 30 element array that's laid out as follows: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 You see, elements 1-6 are in the first row, elements 7-12 are in the second row, etc. This can be represented with the following equasion: elem = ((row - 1) * 6) + column So, to get row 3, column 2, you'd have "((3 - 1) * 6) + 2" which is 14. D Price s 20 3 dim(30) D Cost s 20 3 dim(30) D row s 10I 0 D col s 10I 0 D elem s 10I 0 * Set all prices to 100, costs to 50 c for col = 1 to 6 c for row = 1 to 5 c eval elem = ((row-1) * 6) + col c eval price(elem) = 100 c eval cost(elem) = 50 c endfor c endfor * Set the price(3,2) to 105, cost(3,2) to 55 c eval row = 3 c eval col = 2 c eval elem = ((row-1) * 6) + col c eval Price(elem) = 105 c eval Cost(elem) = 55 You could even convert the EVALs to traditional math functions and use that same type of logic in an RPG III or RPG II program.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.