Go to the first, previous, next, last section, table of contents.


Reversed Equate Constructs

There are two looping constructs and a conditional construct. The basic looping construct has the form [...;...], either side of the semicolon may be null. While the equate expression to the left of the semicolon is true do the equate expression to the right of the semicolon. The expression on the left must leave a boolean value on the stack. An example of this looping construct was given earlier for the definition of strlen. The left and right expressions can include anything, such as nested looping and conditional constructs or function calls.

The other looping construct has the form (...). The expression between the brackets is executed once for every record in the database. For example here is the definition of a function to return the number of records in the master database.

%%EQUATE NRECS 0>>NRECS(++NRECS>>NRECS)<<NRECS

The looping syntax can optionally include a colon suffix form. This allows looping through a named database (if this is the master database then any filtering conditions will be ignored). This form is ():database where database is the name of a valid loaded database (without the pathname or extension). Fields from other databases cannot be accessed within the loop unless the -> syntax is used, so if looping through a database other than the master database then this form must be used within the loop to access fields of the master database. Note that this applies even to nested equate calls within the loop body for example.

The conditional construct has the form ?...:...;. This can take a field name designator, in which case the behaviour is slightly different. The action is to pop a boolean off the stack and if it is true to execute the equate expression up to the colon, and if not to execute the equate expression from the colon up to the semicolon. Each expression can be as complex as required (including nested conditional and looping constructs, and function calls) but need not have any contents. If the ? is immediately followed by a field name and the colon and semicolon fields are null, then if the contents of the field are empty the result is null, else the result is the contents of the field. Below are two examples of the conditional construct.

%%EQUATE SUBDATE1 ?SUB_DATE:"In preparation";
%%EQUATE SUBDATE2 %SUB_DATE""=?"In preparation":%SUB_DATE;

Both the above conditions have the same action. If the %SUBDATE field has a value push the value on the stack, else push the default string on the stack.


Go to the first, previous, next, last section, table of contents.