# a (algebraic) processing code

The a processing code is a recursive algebraic function that creates algebraic formulas and relational operations consisting of operands and operators; these expressions are used by AQL as well as the B-tree indexes. The a processing codes are translated into f processing codes by the AQL compiler. The functional operators and operands for the a processing code are the same as that of the f processing code, except as noted.

 System Processors Select, Update, List Code Type Attribute Defining Dictionary Attributes Input Conversion, Output Conversion, Correlative

## Syntax

```a{{num.digits;}expressions...}
```

## Parameter(s)

 num.digits Argument optionally used to indicate the number of decimal digits (in the range 0 through 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 is 0. expression{s} Expressions formed are like FlashBASIC expressions and consist of operands, operators, conditional statements, and special functions combined together to yield a single resulting value.

D3 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.

## Operands

 number An integer number reference to an attribute count. For example: ```a3*5 ``` This multiplies the value in attribute 3 by the value in attribute 5. number 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 MultiValue attribute. For example: ```a3r*5 ``` This multiplies the first value in attribute 3 by the first value in attribute 5, and returns the result as the first value. Then, it multiplies the first value in attribute 3 by the second value in attribute 5, and returns it as the second value, and so on. number(pr.code{]pr.code...}) An integer number reference to an attribute count, that 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 40 characters, and converts each word to upper and lowercase. Note: Time and date subconversion codes are also supported for FSI indexes and FlashBASIC running as a rule module. 9998 Used as an attribute count specification. Returns the sequential item counter. 9999 Used as an attribute count 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: ```a3*"12" ``` This multiplies the value of attribute 3 of the current item by the constant "12". n(attrname) {(pr.code...)} In this case, n is a literal and indicates that the ADI within the following set of parentheses is to be retrieved. This is sometimes called an indirect reference. This allows a reference to any valid ADI 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 attribute name being referenced in the processing code may in fact reference an item that 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 space, then joins the value of the attribute defined as state with a space 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. lpv Last processing code value (result of the previous processing code). nb Returns the number of the break level. There is a maximum of 255 break levels (0 through 254). The 255th level is reserved for the grand total. This works in attribute 7, the output conversion attribute only. nd Returns the number of detail lines. This works in attribute 7, the output conversion attribute only. ni Returns the sequential number of the item being processed. This works in attribute 7, the output conversion attribute only. ns Returns the sequential number of the subvalue being processed. nv Returns the sequential number of the value being processed. For example: ```nv=s(ac#’!’) ``` t Returns the system time in internal format, meaning the number of seconds past midnight.

## Operators

 Arithmetic Operators + Adds * Multiplies - Subtracts / Divides (note that division operations are rounded down) Concatenation operator : 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 MultiValue results. Substring References ```string.expression[begexp, lenexp] ``` Extracts 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 beginning expression and length expression may be quoted numbers or any expressions that 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 Produce a numeric result. These results are either 1 for a true condition or 0 for a false condition. = Equal to. # Not equal. <= Less than or equal to. >= Greater than or equal to. 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 0, 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 nonzero, 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 previous if. The end is used to close off the current if and associate the else with the previous if. 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" ```
Warning:

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 reconstituted upon output, that is:

• Value entered is 100.25

• Input processing code mr2 stores the value as 10025

• Output processing code mr2 recreates the original value, and outputs as 100.25

Performing arithmetic on two internal values is done as two integers, and care should be taken to rescale 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 place, and descale the result before output. For example:

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

where:

 x Uses attribute number. x(G0.1) Retrieves the integer part. x(G1.1) Retrieves the decimal part. (S;*;"0") Forces trailing zeroes if there is not any decimal point. (ML%5) Normalizes the decimal part into five digits. (MR5) Outputs the number with five decimal places.

Since this must be done with each attribute, the structure of the data can avoid this situation.

Also, it has been reported that the a processing codes do not 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’
```