ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Defining DB fields as an array

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

  • Defining DB fields as an array

    I have an externally described file, SPNOTE that has 15 fields in it SP01, SP02...............SP15. How can I define the 15 fields as an array. The file also has a few other fields like order#, line#

  • #2
    Very messy but you should get the point.

    DData E DS extname(SPNOTE)
    DData1 1 10 DIM(1)
    DData2 10 25 dim(15)
    DCounter S 4 0
    DField1 S 4

    read SPNOTE
    Counter = 1
    Field1 = Data2(Counter)
    etc.....
    Last edited by CaptainRon; November 28, 2023, 11:12 AM.

    Comment


    • #3
      It is rather simple:
      Just Define your File.
      Define a data structure where you list all columns (no need to specify a data type or length ... it is adopted from the file).
      Overlay the data structure with an array ... and you can use the array.
      Something like this:

      Code:
      DCL-F SPNOTE Keyed;
      
      DCL-DS DSListSP;
         SP01;
         SP02;
         SP03;
         SP04;
         SP05;
         SP06;
         SP07;
         SP08;
         SP09;
         SP10;
         SP11;
         SP12;
         SP13;
         SP14;
         SP15;
         SP16;
         ArrSP   Like(SP01)   Dim(15)   Pos(1);
      End-Ds;​
      Last edited by B.Hauser; November 28, 2023, 12:07 PM.

      Comment


      • #4
        Ahh.........it's coming back to me now. I did this before a long time ago.

        Thanks to all

        Comment


        • #5
          You did not specify if SP01-SP16 are all the same type and size. This method will only work if they are all the same.

          Comment

          Working...
          X