Expressions
An expression is a constant, a variable, an array element, a function or a combination of these with one or more operators. The result of an expression will be an integer, a numeric or a text value. Operators are discussed below. Expressions can be used wherever constants can be used: in assignments, in comparisons, as part of a larger expression or as an argument in an ADAPL function.
Arithmetic expressions
If a calculation consists of a number of different expressions (e.g. 2 + 3 * 2 / 10 - 5), Collections will evaluate them in a fixed order. This order corresponds with the standard arithmetic order: exponentiation, multiplication, division, integer modulus, addition, and subtraction. The table below shows the operators that can be used in numeric expressions, in order of evaluation:
|
Operator |
Description |
|
( ) |
Round brackets (parentheses) enclose an independent expression |
|
^ |
Exponentiation |
|
* |
Multiplication |
|
/ |
Division (requires numerical values or variables to produce a numerical result) |
|
\ |
Integer modulus (the remainder of a division) |
|
+ |
Addition |
|
- |
Subtraction |
The following functions with a numeric or integer result are available in arithmetic expressions:
|
Absolute value of a number |
|
|
ASCII value of a character |
|
|
Number of days between two dates |
|
|
Gives the day number for the date (0 is Sunday ... 6 is Saturday) |
|
|
Position of a character in a string |
|
|
The whole (integer) part of a value |
|
|
The actual length of a character string |
|
|
The maximum value of a series of values |
|
|
The minimum value of a series of values |
|
|
The remainder from the division of two values |
|
|
The number of days until (negative value) or since the beginning of 1900 (positive value) |
|
|
The number of occurrences of a tag |
|
|
Searches for a text string in a tag |
|
|
The maximum value in a tag |
|
|
The minimum value in a tag |
|
|
The total of occurrences of a tag |
|
|
The position of a character in a string |
|
|
The rounded value of a number |
|
|
The square root of a number |
|
|
The numeric value of a character string |
One operator is available in ADAPL for text expressions: +. The ‘plus’ sign concatenates text strings. For example:
ERRORM 'He said:' + '''' + 'Hello!' + '''' + '.'
* four consecutive quotes as separate (sub) string are
* required to actually include (display) only one quote (see also ADAPL constants).
The result of this instruction appears on screen: He said: 'Hello!'.
The following functions with a text result are available for text expressions:
|
Returns a substring to the right of indicated character(s) |
|
|
Returns a substring to the left of indicated character(s) |
|
|
Returns a character from the ASCII table |
|
|
Converts from/to upper case |
|
|
Returns the system date as a string |
|
|
Reads the contents of a global system variable |
|
|
Converts a string from Isolatin to HTML |
|
|
Justifies or centres a line |
|
|
The left part of a character string |
|
|
The actual length of a character string |
|
|
Any part of a character string |
|
|
Changes ‘surname, first name’ to ‘first name surname’ |
|
|
Input or mutation date or time as a character string |
|
|
The right-hand part of a character string |
|
|
The rounded value of a number |
|
|
Converts a value to a character string |
|
|
Generates a string of equal characters |
|
|
Returns the name of the tag as entered in the database setup. If no name is filled in there, the tag will be returned |
|
|
Reads line from text file |
|
|
The system time as a character string |
|
|
Removes leading and/or trailing blanks |
|
|
User name or user number as character string |
|
|
Returns a computed date as a character string |
Logical expressions
Logical expressions are expressions that contain logical operators and operators for comparison. The result of a logical expression is either TRUE or FALSE. These values are defined numerically: 0 represents FALSE, any other value represents TRUE.
Integers and numerics are interchangeable for logical expressions. With text comparisons, the value of the logical expression is numeric.
ADAPL allows the following operators for logical expressions:
|
Operator |
Description |
Note |
|
( ) |
Round brackets embed an independent expression |
|
|
= |
Equals. |
String comparisons are always case-sensitive. |
|
< |
Less than or alphabetic precedence |
Number values obtained from database tags must always first be converted to numerics (VAL) and then possibly to integers (INT) before they can be compared as numbers or be used in calculations. |
|
=< or <= |
Less than or equal to |
|
|
> |
Greater than or alphabetic succession |
|
|
=> or >= |
Greater than or equal to |
|
|
<> or >< |
Does not equal |
|
|
AND |
TRUE if both expressions are TRUE |
|
|
NOT |
Reverses the result of the expression following it |
|
|
OR |
TRUE if at least one out of two expressions is TRUE |
|
|
XOR |
TRUE if one expression is TRUE and the other is FALSE |
|
Tag indirection means that the content of a text variable is treated as if it were a database tag. Typically, tag indirection is used when the database tags you wish to use in your code, are also ADAPL reserved words or commands, like for instance the do tag in people.inf (or possible tags like if, is, on, no, or): only* by entering the tag as a string (in between quotes) into the code, ADAPL won't treat it as a command. To put it in other words: you cannot refer anywhere in ADAPL code to a field tag like do, because do is also a reserved word in ADAPL (it can appear in a DO ... UNTIL loop, for example). Only everything in between quotes doesn't conflict with reserved words or commands, because everything in between quotes, is considered a meaningless character string by ADAPL.
Tag indirection is just a clever trick to allow you to use a tag like do still, by changing a meaningless character string into some meaningful still: the idea is that you declare a text variable of sufficient length, then you assign the (meaningless) character string 'do' to it (including the quotes) and from then on, if you'd like to retrieve the contents of the field tag do, you'll use the text variable name with an exclamation mark (the indirection operator) directly in front of it. That way, ADAPL will take the string from the variable but treats it as field tag.
In a before-storage adapl for people.inf for example (where you have direct access to all field tags in the record about to be saved) you could put the contents of tag do via an error message on screen like so:
text tag_var[2]
tag_var = 'do' /* name type
errorm !tag_var
Note that the length of the variable has been set to two because do consists of two characters, but you can set the length to a bigger value too. And the you name the variable any way you like, it doesn't have to be tag_var.
To access a specific occurrence of the tag, simply add the occurrence number enclosed in round or square brackets behind the variable name:
errorm !tag_var[2]
In the above example, field tags from the record were directly accessible because the code was assumed to be part of before-storage code. However, if you need access to a different database table than the one that you're currently working in, you will be using FACS. And if from that other database table you need to retrieve data from tags like do, then what do you do? Because also a FACS declaration is not allowed to contain tags that are also reserved words, nor can you use tag indirection inside a FACS declaration, so you have to solve this differently but still similar to the examples above.
So you can't include the tag in the FACS declaration, but you can still assign it as a string to a text variable. This time though, the FACS name of the dataset must be included in the text variable in front of the tag, separated by a space e.g.:
fdstart MYPEOPLE '../data+people>people'
%0 is MYPEOPLE_priref
BA is MYPEOPLE_name
fdend
open MYPEOPLE
if &E {
errorm 'FACS database table MYPEOPLE could not be opened. Error: ' + &E
end
}
text domain_tag[15]
domain_tag = 'MYPEOPLE do'
read MYPEOPLE using MYPEOPLE_priref = 1
if (&E = 0) {
errorm 'Name and first name type in record 1: ' + MYPEOPLE_name + ', ' + !domain_tag[1]
}
end
Note that you can use the above methods of tag indirection for all tags in an opened (FACS or current) database table, not necessarily only for tags which conflict with reserved words, but then those (non-conflicting) tags do not need to be specified in the FACS declaration.
Reading a FACS database (with the read command) using tag indirection is possible as well, but if that tag is an enumerative field too, then searching will only yield results if the Collections interface language is English. So the following only works in English and therefore shouldn't be used at all:
text domain_tag[15]
domain_tag = 'SUPPLIER do'
read SUPPLIER using !domain_tag = 'SUPPLIER'
* The indirection operator may also appear in a different context, to directly address a tag in a record buffer, including tags which are also reserved words in ADAPL (without using those tags as strings). Records buffers include FACS-declared datasets and adlib_lite (which contains the contents of a currently edited record). For example, to retrieve the contents of the do tag from the currently edited record and display it in an error message, you can also use:
errorm adlib_lite!do
Another example for the case in which a FACS database People has been declared and opened:
if (enumval$(People!do, People!do, -1) = 'AUTHOR'){ … }
Sequence of evaluation in an expression
In the case of compound expressions, Collections will evaluate the various expressions in a fixed sequence. This sequence is based on the standard arithmetic sequence: exponentiation, multiplication, division, addition, and subtraction. Collections adheres to the following order:
| 1. | tag indirection |
| 2. | unary minus (the minus sign of a negative value) |
| 3. | functions |
| 4. | exponentiation |
| 5. | multiplication and division |
| 6. | modulus |
| 7. | addition and subtraction. |
In the event of equal priority, ADAPL will evaluate an expression from left to right.
Expressions and functions can occur within other expressions and functions if they are embedded in round brackets (). The evaluation always begins with the expression in the innermost round brackets, then working outwards. If expressions are used for comparisons, the expressions are evaluated before the comparison is carried out.
The sequence of evaluation in logical expressions is:
| 1. | tag indirection and arithmetic evaluation |
| 2. | comparative operators |
| 3. | logical operators. |
Independent expressions which are embedded in round brackets are evaluated first.

