RECORD
The RECORD
keyword defines a structured type or variable.
Syntax 1 (explicit record definition)
RECORD [
attributes-list ]
member type-specification
[
,...]
END RECORD
- member is an identifier for a record field, that must follow the convention for identifiers.
- type-specification can be one of:
- A primitive type
- A record definition
- An array definition
- A dictionary definition
- A function type definition
- The name of a user defined type
- The name of a built-in class
- The name of an imported extension class
- The name of an imported Java class
- attributes-list is a comma-separated list of name = value pairs or name attributes, and defines attributes for the record type.
Syntax 2 (database column based record)
RECORD [
attributes-list ]
LIKE [
dbname:]
tabname.*
- dbname identifies a specific database schema file.
- tabname.* references the structure of a complete table defined in the database schema file.
- attributes-list is a comma-separated list of name = value pairs or name attributes, and defines attributes for the record type.
Usage
A record defines an ordered set of variables called members. Each record member is defined with a specific type or in turn, structured type.
Consider defining a user type for records, to avoid repeating the record definition for each variable.
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 RECORD
SCHEMA
instruction:SCHEMA stock
...
DEFINE rec RECORD LIKE customer.*
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. If
these differ, the records defined in the your programs will not match the SQL table structures of
the production database.
For example, with an SQL statement such as SELECT * INTO record.* FROM table
,
the columns of the SQL table represented by the *
star in the select list will no
longer match the list of fields represented by record.*
. This can lead to missing
values if columns are been removed from the SQL table, or result in decorrelated values if SQL
columns have been re-ordered in the SQL table. When the SQL column type does not match the target
variable type, conversions error will occur and the SELECT
will fail.
To make sure that the SQL columns match the target record variables, list all SQL columns
explicitly in the SELECT
statement; as in SELECT cust_name, cust_addr,
cust_state INTO record.* FROM ...