× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Interesting.  Thank you for that help.  I think I will use that.  Can I 
use that way in fixed format instead of free format?  We don't use Free 
here ( :(  ) so I'd have to code it in fixed.

Ron Power
Programmer
Information Services
City Of St. John's, NL
P.O. Box 908
St. John's, NL
A1C 5M2
Tel: 709-576-8132
Email: rpower@xxxxxxxxxx
Website: http://www.stjohns.ca/
___________________________________________________________________________
Success is going from failure to failure without a loss of enthusiasm. - 
Sir Winston Churchill




Scott Klement <rpg400-l@xxxxxxxxxxxxxxxx> 
Sent by: rpg400-l-bounces@xxxxxxxxxxxx
07/06/2004 04:55 AM
Please respond to
RPG programming on the AS400 / iSeries <rpg400-l@xxxxxxxxxxxx>


To
RPG programming on the AS400 / iSeries <rpg400-l@xxxxxxxxxxxx>
cc

Subject
Re: 2 dim array







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.
--
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.




This OutBound email has been scanned for Viruses

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

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.