Summary:
See also: Variables, Arrays, Data Types, Database Schema File.
A record defines a structured variable.
DEFINE variable RECORD
member { datatype | LIKE [dbname:]tabname.colname
}
[,...]
END RECORD
DEFINE variable RECORD LIKE [dbname:]tabname.*
In the first form (Syntax 1), record members are defined explicitly. In the second form (Syntax 2), record members are created implicitly from the table definition in the database schema file. The database columns defined as SERIAL will define an INTEGER variable, while SERIAL8/BIGSERIAL columns define BIGINT variables.
Note that 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).
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. See BDL Stack for more details.It is possible to compare records having the same structure with the equal operator: record1.* = record2.*
01
MAIN02
DEFINE rec RECORD03
id INTEGER,04
name VARCHAR(100),05
birth DATE06
END RECORD07
LET rec.id = 5008
LET rec.name = 'Scott'09
LET rec.birth = TODAY10
DISPLAY rec.*11
END MAIN
01
SCHEMA stores02
DEFINE cust RECORD LIKE customer.*03
MAIN04
SELECT * INTO cust.* FROM customer WHERE customer_num=205
DISPLAY cust.*06
END MAIN