[ attr := ] DATASET( recordset , recstruct );
This form allows you to in-line a set of data and have it treated as a file. This is useful in situations where file operations are needed on dynamically generated data (such as the runtime values of a set of pre-defined expressions). It is also useful to test any boundary conditions for definitions by creating a small well-defined set of records with constant values that specifically exercise those boundaries. This form may be used in an expression context.
Nested RECORD structures may be represented by nesting records within records. Nested child datasets may also be initialized inside TRANSFORM functions using inline datasets (see the Child DATASETs discussion).
Example:
//Inline DATASET using definition values
myrec := {REAL diff, INTEGER1 reason};
rms5008 := 10.0;
rms5009 := 11.0;
rms5010 := 12.0;
btable := DATASET([{rms5008,72},{rms5009,7},{rms5010,65}], myrec);
//Inline DATASET with nested RECORD structures
nameRecord := {STRING20 lname,STRING10 fname,STRING1 initial := ''};
personRecord := RECORD
nameRecord primary;
nameRecord mother;
nameRecord father;
END;
personDataset := DATASET([{{'James','Walters','C'},
{'Jessie','Blenger'},
{'Horatio','Walters'}},
{{'Anne','Winston'},
{'Sant','Aclause'},
{'Elfin','And'}}], personRecord);
// Inline DATASET containing a Child DATASET
childPersonRecord := {STRING fname,UNSIGNED1 age};
personRecord := RECORD
STRING20 fname;
STRING20 lname;
UNSIGNED2 numChildren;
DATASET(childPersonRecord) children;
END;
personDataset := DATASET([{'Kevin','Hall',2,[{'Abby',2},{'Nat',2}]},
{'Jon','Simms',3,[{'Jen',18},{'Ali',16},{'Andy',13}]}],
personRecord);
// Inline DATASET derived from a dynamic SET function
SetIDs(STRING fname) := SET(People(firstname=fname),id);
ds := DATASET(SetIDs('RICHARD'),{People.id});
// Inline DATASET derived from a list of transforms
IDtype := UNSIGNED8;
FMtype := STRING15;
Ltype := STRING25;
resultRec := RECORD
IDtype id;
FMtype firstname;
Ltype lastname;
FMtype middlename;
END;
T1(IDtype idval,FMtype fname,Ltype lname ) :=
TRANSFORM(resultRec,
SELF.id := idval,
SELF.firstname := fname,
SELF.lastname := lname,
SELF := []);
T2(IDtype idval,FMtype fname,FMtype mname, Ltype lname ) :=
TRANSFORM(resultRec,
SELF.id := idval,
SELF.firstname := fname,
SELF.middlename := mname,
SELF.lastname := lname);
ds := DATASET([T1(123,'Fred','Jones'),
T2(456,'John','Q','Public'),
T1(789,'Susie','Smith')]);
// You can construct a DATASET from a SET.
SET OF STRING s := ['Jim','Bob','Richard','Tom'];
DATASET(s,{STRING txt});