Accessing Field-level Data in a Specific Record

To access field level data in a specific record, the recordset indexing capability must be used to select a single record. The SORT function and recordset filters are useful in selecting and ordering the recordset so that the appropriate record can be selected.

Example:

TrdRec := RECORD
  UNSIGNED2 Trd_ID;
  INTEGER4 Trd_bal;
  INTEGER4 Trd_hc;
END;
PersonRec := RECORD
  STRING20 FirstName;
  STRING20 LastName;
  DATASET(TrdRec) Trd;
END;
Person := DATASET([{'Fred','Jones',[{1,2,3},{2,4,5}]},
                   {'Sue','Smith',[{10,-2,60},{12,14,50}]},
                   {'Joe','Johnson',[{11,200,3000},{22,140,350},{25,100,850}]},
                   {'Susan','Stone',[{102,2,30},{125,14,50},{225,14000,50000}]}],PersonRec);
Trades := Person.Trd;
ValidMoney(n) := n > 0;
ValidBalTrades := trades(ValidMoney(trades.trd_bal));
HighestBals := SORT(ValidBalTrades,-trades.trd_bal);
Highest_HC := EVALUATE(HighestBals[1],trades.trd_hc);
    //return trd_hc field of the trade with the highest balance
    // could also be coded as (using indexing):
    // Highest_HC := HighestBals[1].trades.trd_hc;

OUTPUT(Person,{lastname,firstname,Highest_HC});
    //output that Highest_HC for each person
    //This output operates at the scope of the Person record
    // EVALUATE is needed to get the value from a Trades record
    // because Trades is a Child of Person

See Also: SORT