× 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.




How can I covert this DS to an Array of 25 Elements each.
Do I have to define DIM() on each field or only on 1st line.

If you change it to a qualified data structure, you can simply put DIM on the first line. For example:



D CITEMSTR DS qualified dim(25) D MCN2 15 D MSN 5I 0 D MACODE1 10 D MQTY1 5I 0 D MPRICE1 12 2 D MAMOUNT1 12 2

Then you reference it in your code as:

     citemstr(x).msn = 123

An older alternative is to use a multiple occurrence data structure. With that, it doesn't have to be qualified:

     D CITEMSTR        DS                    occurs(25)
     D  MCN2                         15
     D  MSN                           5I 0
     D  MACODE1                      10
     D  MQTY1                         5I 0
     D  MPRICE1                      12  2
     D  MAMOUNT1                     12  2

Then, you use the %occur() BIF (or the OCCUR op-code) to switch which ocurrence you're working with at any given time.

      %occur(CITEMSTR) = x;
      msn = 123

The final option is to create a group field that can be DIMed, and have all of the elements of your array overlay that group field:

     D CITEMSTR        ds
     D   group                             dim(25)
     D   MCN2                        15    overlay(group:*next)
     D   MSN                          5I 0 overlay(group:*next)
     D   MACODE1                     10    overlay(group:*next)
     D   MQTY1                        5I 0 overlay(group:*next)
     D   MPRICE1                     12  2 overlay(group:*next)
     D   MAMOUNT1                    12  2 overlay(group:*next)

Now you can reference each field in the DS as an array, if you like:

     MSN(x) = 123;

Each method has it's pros and cons (well, okay, I can't think of any pros for the %occur method, aside from the fact that it existed in RPG/400) so which you use will probably depend on what you're trying to accomplish.

Good luck


As an Amazon Associate we earn from qualifying purchases.

This thread ...

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.