a (algebraic)

a (algebraic)


Processing Codes Index Level algebraic function
Syntax a{num.digits}{;}expression{s}  
Category Processing Codes
Type Processing Code
Description recursive algebraic function which creates algebraic formulas and relational operations consisting of operands and operators; these expressions are used by Access as well as the b-tree indices.

"a" processing codes are translated into "f" processing codes by the Access compiler.

The functional operators and operands for the "a" processing code are the same as that of the "f" Processing Code, except as noted.

The "num.digits" argument is optionally used to indicate the number of decimal digits (in the range 0-4) to retain during calculations involving a mixture of whole numbers and numbers with implied decimals, along with "m" (mask) processing codes in the body of the function. The default "num.digits" is zero.

The expressions formed are like FlashBASIC expressions and consist of operands, operators, conditional statements and special functions combined together to yield a single resulting value.

Pick algebraic processing uses a "last-in first-out" stack. Operands are pushed onto the top of the stack and all existing stack entries shift down. Operations operate on the top first, second, or third stack entries, depending on the operation. Results processing, including additional conversions, take the top value off the stack.

The available operands include:

number  

An integer number reference to an attribute count ("ac"). For example:  

 a3*5

This multiplies the value in attribute 3 by the value in attribute 5.

numberr

A reference to an attribute count, with a "repeat" code, meaning that the first value of the attribute is to be used (repeated) when using this attribute against another multi-valued attribute. For example:  

 a3r*5

This multiplies the 1st value in attribute 3 by the 1st value in attribute 5, and returns the result as the first value. Then, it will multiply the 1st value in attribute 3 by the 2nd value in attribute 5, and return it as the second value, and so on.

number(processing.code{]processing.code...})

The "number" is an integer reference to an attribute count ("ac"), which may be immediately passed through any other valid processing code, except another "a" or "f" processing code or an index processing code. Multiple processing codes may be specified and each separate processing code must be delimited by a value mark (represented in the syntax with the "]" character). For example:

 a1(t1,40]mct)

This retrieves attribute 1 of the current item, extracts the first forty characters, and converts each word to upper and lower case.

9998

Used as an "ac" specification. Returns the sequential item counter.

9999

Used as an "ac" specification. Returns the size of the item in bytes.

"text"

Any quoted text or numeric string, which is treated as a literal. For example:  

 a"Attention: ":1

This concatenates the literal, "Attention: ", to the contents of attribute 1 of the current item.

An example of a numeric constant is as follows:  

 a3*"12"

This multiplies the value of attribute three of the current item by the constant "12".

n(attrname){(processing.code...)}

In this case, "n" is a literal and indicates that the attribute-defining item within the following set of parentheses is to be retrieved. This is sometimes called an "indirect" reference. This allows a reference to any valid attribute-defining item in the dictionary of the file being accessed. The string returned with this operand may subsequently be passed through one or more other valid processing codes (except another "a" or "f" processing code or an index processing code) as long as each is separated by a value mark. This is where recursion occurs, as the attrname being referenced in the processing code may in fact reference an item which also contains an "a" processing code. For example:  

 an(city):", ":n(state):" ":n(zip)

This concatenates the contents of the attribute defined as "city" with a comma and a blank, then joins the value of the attribute defined as  "state" with a blank and then appends the attribute defined as "zip" to the end of the string. For example:

an(city):", ":n(state)(tstates;c;;1):" ":n(zip)

This is like the previous example, but this time the value in the "state" attribute is "translated" to the "states"
file, returning attribute 1 of the corresponding item.

d  Returns the system date in internal form. For example:

 a(d-n(invoice.date))

This subtracts the value of "invoice.date" from the current system date, which determines the number of days that have elapsed since the date of the invoice.

nb  Returns the number of the break level. There is a maximum of 255 break levels (0 - 254). The 255th level is reserved for the grand total. This works in attribute 7, the "conversion" attribute, only.

nd  Returns the number of detail lines. This works in attribute 7, the "conversion" attribute, only.

ni  Returns the sequential number of the item being processed. This works in attribute 7, the "conversion" attribute, only.

nv  Returns the sequential number of the value being processed. For example:

 nv=s(ac#'!')  

ns  Returns the sequential number of the subvalue being processed.

t  Returns the system time in internal format, meaning the number of seconds past midnight.


The available operators include:

Arithmetic Operators:

+ add
* multiply
- subtract
/ divide (note that division operations are rounded down.)

Concatenation Operator:

: (colon) Concatenates two operands.

Boolean Operators:

AND Logically AND operand one to operand two.

OR Logically OR operand one to operand two.


Arithmetic Functions:

r(expression1,expression2)

Returns the remainder of expression1 divided by expression2.

s(expression)

Sums multi-valued results.


Substring References:  

string.expression[begexp,lenexp]

Used to extract a fixed number of characters from a string expression. The "begexp" (beginning position expression) specifies the beginning character position and the "lenexp" (length expression) specifies the length, or number, of characters to retrieve. The begexp and lenexp may be quoted numbers or any expressions which derive numeric results. For example:

a"(":n(phone)["1","3"]:") ":n(phone)["4", "3"]:"-":n(phone)["7","4"]

This takes a phone number stored as "7145551212" and outputs it as "(714) 555-1212".


Relational Operators:

Relational operators produce a numeric result. These results are either 1 (one) for a true condition or 0 (zero) for a false condition.

= Equal to.  If operand1 = operand2 then 1 else 0
# Not equal.  If operand1 # operand2 then 1 else 0 < Less than.  If operand1 < operand2 then 1 else 0 > Greater than.  If operand1 > operand2 then 1 else 0
<= Less than or equal to.  If operand1 <= operand2 then 1 else 0
>= Greater than or equal to.  If operand1 >= operand2 then 1 else 0


Conditionals:

Conditionals are constructed using a syntax very similar to the FlashBASIC "if...then...else" construct and have the general form:

If condition then algebraic function { else algebraic function } {end}

if condition else algebraic function {end}

if condition then algebraic function {end}

If the condition evaluates to zero, it is considered false and, if present, the "else" clause is taken. If the evaluation is false, and the "else" clause is missing, a null is returned.

If the condition evaluates to non-zero, it is considered true, and, if present, the "then" clause is taken. If the evaluation is true, and there is no "then" clause, a null is returned.

If END is not specified, the ELSE is paired with the nearest previous IF. The END is used to close off the current IF and associate the ELSE with the prior IF.

For example:

if 1 then if 2 then "1 and 2 true" end else "1 false"

Note: if 1 is true and 2 is false, null is returned.

Conditional options:

"condition":  An algebraic function (a processing code).

"algebraic function":  An algebraic function (a processing code).

Examples:

if 1 > 2 then n(attr1) else n(attr2) end

if 1 > 2 then if 3 then 3 else 4

if (if 1 then 2 else 3) then "true"
Options
See Also nframe-index c (concatenate) output-conversion output-conversion ac input-conversion id (assign id) create-index b-tree algebraic function ROOT processing codes delete-index i (index, File-defining Item) verify-index correlative processing codes (adi) string.expression if i (index, local) u01ad y z s (substitution) f-correlative Processing Codes Reverse Polish Notation *A9999 correlative processing codes (fdi)
Example
Warnings Arithmetic within a processing code is always integer arithmetic, so any value with a decimal fraction is truncated.

The attribute values should be stored without a decimal point, and are re-constituted upon output, i.e., The value entered is: "100.25"; The input processing code "MR2" stores the value as "10025"; The output processing code "MR2" re-creates the original value, and outputs it as: "100.25"

Performing arithmetic on two internal values will then be done as two integers, and care should be taken to re-scale the result properly to preserve the proper placement of the decimal place.

Division by 0 produces a result of 0 with no error message.

If arithmetic must be performed on internal values that contain a decimal point, then the processing code must "normalize" the value to a number with a fixed number of decimal places, and then de-scale the result before output.

Here is an example:

Fx(G0.1);x(G1.1);(S;*;"0");(ML%5);:(MR5);

where:

"x" is the attribute-number to use.

"x(G0.1)" retrieves the integer-part.

"x(G1.1)" retrieves the decimal part.

"(S;*;"0")" forces trailing zeroes if there isn't any decimal point.

"(ML%5)" normalizes the decimal-part into 5 digits.

"(MR5)" outputs the number with 5 decimal places.

Since this must be done with each attribute, it would be wiser to add a little forethought into the structure of the data and avoid this situation.

Also it has been reported that "a" processing codes will not tolerate or handle "index" processing codes. For example, using an "input-conversion" of "A1(Ifilename;A0)" results in the error message: "[367] illegal f-correlative.: 'A1(Ifilename;A0'".
Compatibility D3 7.0 AP R83
Processing Codes Index Level algebraic function