ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Array

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

  • Array

    I read a file and there are four fields same type
    Gift code

    2,000 P
    1,500 Q
    3,000 P
    2,500 P

    I want to put these in an array and then sort them decsending. Do i use a runtime array and put them in a D spec. Looking for some help with D spec and the code in the C spec? Thanks

  • #2
    Re: Array

    select field1 , field2
    from myfile
    order by field1 Desc

    or
    D MyArray S 4S 0 dim(999)
    /free
    X = X+1;
    Read Myfile;
    dow not %EOF(MyFIle);
    MyArray(x) = Myfield;
    Read Myfile;
    EndDo;

    SortA MyArray;

    http://www.itjungle.com/fhg/fhg092910-story01.html

    But seriously do it in SQL.
    Hunting down the future ms. Ex DeadManWalks. *certain restrictions apply

    Comment


    • #3
      Re: Array

      If I understand correctly, the OP wants to sort FLD1 FLD2 FLD3 and FLD4 from a single record.

      dcl-s myArray like(fld1) dim(4);

      myArray(1) = fld1;
      myArray(2) = fld2;
      myArray(3) = fld3;
      myArray(4) = fld4;
      sorta(d) myArray;

      Comment

      Working...
      X