Language basics / Records |
Records define structured variables.
DEFINE variable RECORD [ ATTRIBUTES( attribute [ = "value" ] [,...] ) ] member { datatype | LIKE [dbname:]tabname.colname } [ ATTRIBUTES( attribute [ = "value" ] [,...] ) ] [,...] END RECORD
DEFINE variable RECORD [ ATTRIBUTES( attribute [ = "value" ] [,...] ) ] LIKE [dbname:]tabname.*
A record is an ordered set of variables (called members), where each member is defined with a specific type or in turn, structured type.
Records whose members correspond in number, order, and data type compatibility to a database table can be useful for transferring data from the database to the screen, to reports, or to functions.
DEFINE rec RECORD cust_id INT, cust_name VARCHAR(50), cust_address VARCHAR(100), ... END RECORDIn the second form (Syntax 2), record members are created implicitly from the table definition found in the database schema file specified by the SCHEMA instruction:
SCHEMA stock ... DEFINE rec RECORD LIKE customer.*
DISPLAY rec.*
CALL myfunction(rec.*)
LET rec2.* = rec3.* ... IF rec1.* == rec2.* THEN ... END IF
When comparing records, all members will be compared. If two members are NULL, the result of this member comparison results in TRUE.
Records can be defined with the ATTRIBUTES() clause, to specify meta-data information for the record. This feature is especially used when defining records for XML-based Web Services. For more details about XML attributes, see Attributes to customize XML serialization.