Records

A record is a data structure that contains one or more columns along with an expression that determines the datatype and value for the column. One or more columns in the record can be defined as key columns. Each record also has an operation code with the default operation code being "insert". The compiler implicitly determines the type for each of the columns based on the type of the column expression. A record that is created can be output to a stream or stored in a record variable with a compatible record type.

Record Event Details

A record type contains one or more column names, each associated with a datatype. One or more of the columns can be identified as key columns.

You can declare a record type inside any block of SPLASH code, including Global/Local declare blocks, functions, and the ON method of a Flex operator using the following syntax:

[ [columnType column; [...] [|] ] name

or

[ [ columnType column; [...] | ] columnType column; [...] ] name
          

columnType is the datatype of the column. column is the name of the column in the record. A column name must be unique within a record and is case-sensitive. name is the name of the record type

The outer square brackets are part of the syntax and do not represent an optional element. Any columns appearing before the | character represent the key columns in the record type. The semicolon following the last column before the key separator | and/or the trailing ] is optional.

The following example declares a record variable called traderec with the specified record definition that has two key columns, TradeId and Symbol, and three other columns, Volume, Price and TradeTime:

[ integer TradeId; string Symbol; | integer Volume; float Price; date TradeTime; ] traderec;

The previous example

Record Details

You can define a record in SPLASH inside any Global/Local function and inside the ON Method of a Flex Operator. To define a record, use the following syntax:
[  column = value;  [...] [|] ]

or

[  [ column = value; [...]  |  ]   column = value; [...]   ] 
          

column is the name of a column in the record. A column name must be unique within a record and is case-sensitive.

value is a value of any datatype. The column type is determined by the compiler based on this datatype.

The outer square brackets are part of the syntax and do not represent an optional element. Any columns appearing before the | character represent the key columns in the record type. The semicolon following the last column before the key separator | and/or the trailing ] is optional.

When a record is created its opcode is set to 'insert' by default. You can change the operation code using the setOpcode function as described in the following example:

[ integer TradeId; string Symbol; | integer Volume; float TradePrice; date TradeTime; ] traderec;
traderec := [ TradeId = 1; Symbol = 'SAP'; | Volume = 100; TradePrice = 150.0; undate('2012-03-01 10:30:35'); ];

In the above example the record variable traderec is assigned a record object with particular values.

Operations on Records

Operations on records:

Record Casting Rules

The ESP compiler does the necessary implicit casting when assigning a source record to a target record variable where the types and column names do not match exactly. This allows you to assign either a source record to a target that does not have all the columns in the target, or a source that has more columns than the target record variable type. The following casting rules are used by the compiler:

In the following example, the volume and TradeCost columns in outTrade are set to NULL because there are no corresponding columns in the source record srcTrade. Symbol is cast as an attribute column in the target, even though it is a key column in the source.

[ integer TradeId; string Symbol; | integer Volume; float TradePrice; date TradeTime; ] srcTrade;
[ integer TradeId; | string Symbol; integer volume; float TradeCost; date TradeTime; ] outTrade;

outTrade := srcTrade
Note: Casting is an expensive operation. Where possible, explicitly create a source record of the same type as the target record.