Back to Contents


Records

Summary:

See also: Variables, Arrays, Data Types, Database Schema File.


Definition

Purpose:

A record defines a structured variable.

Syntax 1:

RECORD
  member { type | LIKE [dbname:]tabname.colname }
  [,...]
END RECORD

Syntax 2:

RECORD LIKE [dbname:]tabname.*

Notes:

  1. A record is an ordered set of variables (called members), where each member can be of any data type, a record, or an array.
  2. 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.
  3. In the first form (Syntax 1), record members are defined explicitly.
  4. In the second form (Syntax 2), record members are created implicitly from the table definition in the database schema file.
  5. member is an identifier for a record member variable.
  6. type can be any data type, a record definition, or an array definition.
  7. When using the LIKE clause, the data type is taken from the database schema file. Columns defined as SERIAL are converted to INTEGER.
  8. dbname identifies a specific database schema file.
  9. tabname identifies a database table defined in the database schema file.
  10. colname identifies a database column defined in the database schema file.
  11. In the rest of the program, record members are accessed by a dot notation (record.member).
  12. The notation record.member refers to an individual member of a record.
  13. The notation record.* refers to the entire list of record members.
  14. The notation record.first THRU record.last refers to a consecutive set of members. (THROUGH is a synonym for THRU).
  15. Records can be used as function parameters, and can be returned from functions.

Tips:

  1. It is possible to compare records having the same structure with the equal operator: record1.* = record2.*

Warnings:

  1. When using the LIKE clause, the data types are taken from the database schema file during compilation. Make sure that the 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.

Examples

Example 1:

01 MAIN
02   DEFINE rec RECORD
03               id INTEGER,
04               name VARCHAR(100),
05               birth DATE
06             END RECORD
07   LET rec.id = 50
08   LET rec.name = 'Scott'
09   LET rec.birth = TODAY
10   DISPLAY rec.*
11 END MAIN

Example 2:

01 SCHEMA stores
02 DEFINE cust RECORD LIKE customer.*
03 MAIN
04   SELECT * INTO cust.* FROM customer WHERE customer_num=2
05   DISPLAY cust.*
06 END MAIN