TABLE(recordset, format [, expression [,FEW | MANY] [, UNSORTED]] [, LOCAL] [, KEYED ] [, MERGE ] [, SKEW(limit[, target] ) [, THRESHOLD(size) ] ] [, UNORDERED | ORDERED( bool ) ] [, STABLE | UNSTABLE ] [, PARALLEL [ ( numthreads ) ] ] [, ALGORITHM( name ) ] )
The TABLE function is similar to OUTPUT, but instead of writing records to a file, it outputs those records in a new table (a new dataset in the supercomputer), in memory. The new table is temporary and exists only while the specific query that invoked it is running.
The new table inherits the implicit relationality the recordset has (if any), unless the optional expression is used to perform aggregation. This means the parent record is available when processing table records, and you can also access the set of child records related to each table record. There are two forms of TABLE usage: the "Vertical Slice" form, and the "CrossTab Report" form.
For the "Vertical Slice" form, there is no expression parameter specified. The number of records in the input recordset is equal to the number of records produced.
For the "CrossTab Report" form there is usually an expression parameter and, more importantly, the output format RECORD structure contains at least one field using an aggregate function with the keyword GROUP as its first parameter. The number of records produced is equal to the number of distinct values of the expression.
Example:
//"vertical slice" form:
MyFormat := RECORD
STRING25 Lname := Person.per_last_name;
Person.per_first_name;
STRING5 NewField := '';
END;
PersonTable := TABLE(Person,MyFormat);
// adding a new field is one use of this form of TABLE
//"CrossTab Report" form:
rec := RECORD
Person.per_st;
StCnt := COUNT(GROUP);
END
Mytable := TABLE(Person,rec,per_st,FEW);
// group persons by state in Mytable to produce a crosstab
See Also: OUTPUT, GROUP, DATASET, RECORD Structure