DEFINE ... RECORD

Records define structured variables.

Syntax 1 (explicit record definition)

DEFINE variable RECORD
  [ ATTRIBUTES( attribute [ = "value" ] [,...] ) ]
  member {
              datatype
           |
              LIKE [dbname:]tabname.colname
           }
           [ ATTRIBUTES( attribute [ = "value" ] [,...] ) ]
  [,...] 
END RECORD

Syntax 2 (database column based record)

DEFINE variable RECORD
    [ ATTRIBUTES( attribute [ = "value" ] [,...] ) ]
    LIKE [dbname:]tabname.*
  1. variable defines the name of the record.
  2. member is an identifier for a record member variable.
  3. datatype can be any data type, a record definition, a user defined type, an array definition, a built-in class, an imported package class, or a Java™ class.
  4. dbname identifies a specific database schema file.
  5. tabname identifies a database table defined in the database schema file specified by SCHEMA.
  6. colname identifies a database column defined in the database schema file specified by SCHEMA.
  7. attribute is an attribute to extend the record or record member definition with properties.
  8. value is the value for the record definition attribute, it is optional for boolean attributes.

Usage

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.

In the first form (Syntax 1), record members are defined explicitly:
DEFINE rec RECORD
           cust_id INT,
           cust_name VARCHAR(50),
           cust_address VARCHAR(100),
           ...
       END RECORD
In 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.*
Important: When using the LIKE clause, the data types are taken from the database schema file during compilation. Make sure that the database schema file of the development database corresponds to the production database, otherwise the records defined in the compiled version of your programs will not match the table structures of the production database. Statements like SELECT * INTO record.* FROM table would fail.
In the rest of the program, record members are accessed by a dot notation (record.member). The notation record.member refers to an individual member of a record. The notation record.* refers to the entire list of record members. The notation record.first THRU record.last refers to a consecutive set of members. (THROUGH is a synonym for THRU):
DISPLAY rec.*
Records can be passed as function parameters, and can be returned from functions. However, when passing records to functions, you must keep in mind that the record is expanded as if each individual member would have been passed as parameter:
CALL myfunction(rec.*)
It is possible to assign and compare records having the same structure, by using the dot star notation:
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.