Unconfigured Ad Widget

Collapse

Announcement

Collapse
No announcement yet.

Help with Array

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help with Array

    Bret, The following code is from one of my programs. AMV1..AMV13 are the external field names.
    D DS DAMV 1 52P 0 DIM(13) DAMV1 1 4P 0 DAMV2 5 8P 0 DAMV3 9 12P 0 DAMV4 13 16P 0 DAMV5 17 20P 0 DAMV6 21 24P 0 DAMV7 25 28P 0 DAMV8 29 32P 0 DAMV9 33 36P 0 DAMV10 37 40P 0 DAMV11 41 44P 0 DAMV12 45 48P 0 DAMV13 49 52P 0 
    Hope this helps. John P.

  • #2
    Help with Array

    John, Thanks. I had coded one similar to this, but I was forgetting to increase the size of the 'array field' to be the combined size of the elements. -bret

    Comment


    • #3
      Help with Array

      Bret, you can load arrays a couple of ways: 1. use I-spec rename (this is an RPG III way). D months S like(month01) dim(12) Irec I month01 months(1) I month02 months(2) ... I month12 months(12) 2. define an overlay array: D monthsDS ds D month01 (don't put anything here) D month02 ... D month12 D months like(month01) D overlay(monthsDS) Bret Myrick wrote: > > Hello Everybody! > > I have not used arrays and elements in quite a while. I have a > question about loading and using them in RPG/IV. > > I have 12 bucket fields of 9p 4 decimal fields. Dollars for month 1 - > 12. > > I want to load the 12 elements of the array with the 12 fields from > the file. I then want to process them based on the month that is > passed to the program. > > I can remember that I access them like: c eval x=array(y), but how in > the world do I load them. With RPG/II/III, I would create a data > structure field and move that field into the array. > > What is the best method of doing this with RPG/IV? > > Thanks in advance, > > Bret

      Comment


      • #4
        Help with Array

        Barbara, d a_bucks ds d sbuhp01 d sbuhp02 d sbuhp03 d sbuhp04 d sbuhp05 d sbuhp06 d sbuhp07 d sbuhp08 d sbuhp09 d sbuhp10 d sbuhp11 d sbuhp12 d months like(sbuhp01) d overlay(a_bucks) Here is what I keyed in. Code/400 gave many, many lines of the horrible blue error messages. Help!!!!! -bret

        Comment


        • #5
          Help with Array

          Bret - If the fields are contiguous in your file, I think you can define an external data structure of that format, create a character subfield using from and to notation (60 long I think, as you said twelve 9p 4 fields, and define your array as 9p 4 DIM(12) OVERLAY(char-field). Bill

          Comment


          • #6
            Help with Array

            Yikes! What did the error messages say? Did you have the member type set to RPGLE? Bret Myrick wrote: > > Barbara, > > d a_bucks ds > d sbuhp01 ... > d sbuhp11 > d sbuhp12 > d months like(sbuhp01) > d overlay(a_bucks) > > Here is what I keyed in. Code/400 gave many, many lines of the > horrible blue error messages. > > Help!!!!! > > -bret

            Comment


            • #7
              Help with Array

              Here's are a few ways I use arrays in RPGIV:
               * Array to determine: (1) Stop-off sequence * (2) Load sequence * (3) Number of orders d ds d Orders 18 dim(5) inz(*hival) d AssocOrder 6s 0 overlay(Orders : 1) d LoadSeq 6s 0 overlay(Orders : 7) d StopOff 2s 0 overlay(Orders : 13) * Subfields of file IGECXL04 to create arrays for ECAS01 - ECAS05 * and ECOL01 - ECOL05. d e ds ExtName(IGECXL04) d ECAS 6 25p 0 Dim(5) d ECOL 48 52p 0 Dim(5) * Error Message d ErrorMsg s 80 Dim(2) CtData PerRcd(1) 

              Comment


              • #8
                Help with Array

                To avoid having to hard-code the from and to positions, you could define a based array LIKE(one-of-the-fields) and set the basing pointer to the address of the first subfield. Ffile if e disk D extds e ds extname(file) D array s like(sbuhp01) D based(pArray) D pArray s * inz(%addr(sbuhp01)) Bill R Adams wrote: > > Bret - > > If the fields are contiguous in your file, I think you can define an > external data structure of that format, create a character subfield > using from and to notation (60 long I think, as you said twelve 9p 4 > fields, and define your array as 9p 4 DIM(12) OVERLAY(char-field). > > Bill

                Comment


                • #9
                  Help with Array

                  Bret, Rename your fields in the "I" specs to an element of the array. Once this is done, you need only enter a single line of "D" specs defining the array. Dave

                  Comment


                  • #10
                    Help with Array

                    Comment


                    • #11
                      Help with Array

                      David, I found what I was doing. I had a definition for the D-spec with 'sub elements' of each field that made up the data structure. I was not moving the data structur to the array. Duhh!!!!!!! -bret

                      Comment


                      • #12
                        Help with Array

                        Hello Everybody! I have not used arrays and elements in quite a while. I have a question about loading and using them in RPG/IV. I have 12 bucket fields of 9p 4 decimal fields. Dollars for month 1 - 12. I want to load the 12 elements of the array with the 12 fields from the file. I then want to process them based on the month that is passed to the program. I can remember that I access them like: c eval x=array(y), but how in the world do I load them. With RPG/II/III, I would create a data structure field and move that field into the array. What is the best method of doing this with RPG/IV? Thanks in advance, Bret

                        Comment


                        • #13
                          Help with Array

                          I don't see the dim keyword? Do you not have to code the dim keyword? Tell me if the code here is correct or if there is something missing. I really would appreciate it. Thanks
                          Code

                          Comment


                          • #14
                            Help with Array

                            Oops, you're right. You need DIM(12) on the UnitArray definition.

                            Comment

                            Working...
                            X