I-Type Expressions

Top  Previous  Next

 

The difference between a D-type and an I-type dictionary item is perhaps best illustrated by a simple example. A file might contain information about employees including their date of birth. If we want to list all employees with their date of birth we could do this by a query of the form

 

LIST EMP.FILE NAME DOB

 

If we want the employee's age, this data is not recorded and, of course, changes with time. However, by creating an I-type called AGE we could simply enter

 

LIST EMP.FILE NAME AGE

 

What is in this I-type?  It is a simple program which calculates the employee's age using the DOB field and today's date.

 

Any I-type has an expression in field 2. This is constructed from the following components:

 

Field names (D or I-type)

Constants

@ variables

Operators

QMBasic functions

Special functions

 

The AGE I-type referred to above is actually more complex than it may at first seem. It might be written as

 

OCONV(DATE(), "D4Y") - OCONV(DOB, "D2Y"); IF OCONV(@DATE,"DMD") > OCONV(DOB,"DMD") THEN @ + 1 ELSE @

 

An I-type must be compiled before it can be used and whenever the dictionary is changed in a manner that would affect fields used by the I-type. The COMPILE.DICT (synonym CD) command compiles one or more I-types in a dictionary. The MODIFY command also provides facilities to compile I-types when they are edited and the query processor commands all compile a previously uncompiled I-type when it is first used.

 

An I-type expression consists of one or more elements each of which is similar to a QMBasic expression.

 

Whereas a QMBasic program would refer to variable names, an I-type expression uses field names as defined in the file's dictionary. These names may be either D or I-type items.

 

Many of the @­variables used by QMBasic are also available in I-types. The following @-variables are specific to I-types though some can be used by QMBasic programs to set up the working environment for the I-type.

 

@FILE.NAMEThe name of the file being processed by the command.

 

@IDThe record id of the current record.

 

@NBBreak level number.

 

@NIItem counter.

 

@RECORDThe data of the record being processed by the command.

 

A compound I-type has multiple elements separated by semicolons. The value of the previous element may be referred to by the symbol @ and the value of a specific element as @n where n is the element number, starting at one. The overall value of the I-type is the value of the final expression.

 

To simplify editing of compound I-type expressions, the "edit values" mode of both the ED and SED editors can be used to break the expression such that each element appears on a separate line.

 

Most QMBasic functions are also available in I-type expressions. The following functions are either specific to I-type expressions or modified from their QMBasic form:

 

TOTAL()

TRANS()

SUBR()