The A code is a function that uses an algebraic format. There are two forms of the A code:
A Uses only the integer parts of stored numbers unless a scaling factor is included.
AE Handles extended numbers, that is, it uses both the integer and fraction parts of stored numbers.
The A code has arithmetic, relational, logical, and concatenation operators. It allows data to be referenced by attribute names as well as by AMC. It gives you the capability to use other data definition items as functions that return a value. It also allows you to modify data by means of format codes.
In handling the A code, the processor changes it to F code format before performing the function. Some error messages that you might see reflect this.
Output conversion is valid.
Input conversion is not allowed: the processor displays an error message.
A{n}{;expression}
or
AE;expression
n is a number (1-6) to specify a desired scaling factor.
expression consists of operands, operators, conditional statements, and special functions.
You can use the A code in these formats:
A;expression Evaluates the expression and compiles into an F;expression function.
An Converts to a scaled integer.
An;expression Converts to a scaled integer and compiles into an Fn;expression function.
AE;expression Evaluates the expression and compiles into an FE;expression function.
The F code functions are described under the heading F Code - Mathematical Functions.
The An format converts a value stored with an embedded decimal point (such as values generated by ALL) to a scaled integer for use by an English sentence. The stored value is multiplied by the power of 10 as specified by n (where n is a number, 1 to 6) and rounded to the nearest integer. If n = 0, ;expression cannot be specified.
Attribute 2 of the data definition item must contain the AMC of the attribute that contains the data to be processed.
The An;expression format performs the functions specified in expression on values stored with an embedded decimal (such as ALL-generated values). The resulting value is then converted to a scaled integer for use by an English sentence.
If this data definition item is to be referenced by name from another function, attribute 2 must contain a zero.
The AE format uses stored numbers as they are, both integers and fractions. The function handles up to nine decimal places. Scaling of output must be done with format codes.
Each of the function codes below adds the contents of attribute 1 to the contents of attribute 2. The A code adds integers only; the An code scales up each operand before adding them; the AE code adds the fractional part as well as the integer part.
Attribute 1 Attribute 2 A;1+2 A3;1+2 AE;1+2 6 023 29 29000 29 -99 -99 -99000 -99 0.34 45.09 45 45430 45.43 -3.123 -12.34 -15 -15463 -15.463 -3.123 123.45 120 120327 120.327
The operators that you can use in A code expressions include arithmetic, relational and logical operators, the concatenation operator, and the IF statement.
+ Sum of operands.
- Difference of operands.
* Product of operands.
/ Quotient of operands.
Note: Division by zero returns the dividend.
Relational operators specify logical relational operations. Two expressions are treated as operands and evaluated as true (1) or false (0). The following are valid relational operators:
= or EQ Equal to.
< or LT Less than.
> or GT Greater than.
<= or =< or LE Less than or equal to.
>= or => or GE Greater than or equal to.
# or NE Not equal.
In the following example, the sum of attributes ACT and PRI is multiplied by .07. If the result is greater than 0, then the word CREDIT is output. Otherwise the word DEBIT is output:
A;IF N(ACT)+N(PRI)*".07">"0" THEN "CREDIT" ELSE "DEBIT"
The logical operators AND and OR combine two expressions into one value, 0 or 1:
AND If both expressions are true, the AND operation yields 1; else, 0.
OR If at least one of the expressions is true, OR yields 1; else, 0.
The words AND and OR must be followed by at least one space.
The AND operator takes precedence over the OR unless you specify a different order by means of parentheses.
A colon (:) concatenates the results of two expressions. For example, the following expression adds the values in attributes 5 and 6 and concatenates the result with the value in attribute 3:
A;5+6:3
The operands that you can use in A code expressions are attribute numbers (AMC), attribute names, literals, operands that return system parameters, and special functions.
attribute-number{R{R}}
Value of the attribute.
D System date (internal format).
I(expression) Integer part of expression.
"literal" Literal value.
LPV Previous value transformed by a format code.
N(attribute-name){R{R}}
Value as defined by the data definition item.
NA Number of attributes in the item.
NB Current break level counter:
1 = lowest break level
255 = GRAND-TOTAL line.
ND Number of items (detail lines) since the last control break.
NF{c} The file specifier. The third character, if present, specifies a particular part of the file specifier; see Operand System Parameters for details.
NI Item counter.
NL Item length.
NS Subvalue counter.
NU Date of last update.
NV Value counter.
R(exp1,exp2) Remainder of exp1/exp2.
Note: If exp2 evaluates to 0, the result is 0.
S(expression) Sums all values generated by expression.
string[s,n] Substring starting at character s of length n.
T System time (internal format).
V Previous value transformed by a format code.
@(exp1,exp2,exp3)
if exp1 evaluates to true, returns value of exp2; otherwise
returns value of exp3.
You can format an operand by following it with parentheses enclosing one or more format codes separated by value marks:
operand(format-code{]format-code}...)
Refer to the Format Codes section later in this topic for more details.
An attribute number (AMC) specifies the attribute containing the value(s) to be used. Attribute numbers 0, 9998, and 9999 have special meanings.
attribute-number{R{R}}
The following attribute numbers have special meanings:
0 Item-id
9999 Item size in bytes
9998 Sequential item count
R An attribute reference followed by R specifies that a single value is to be used repeatedly when evaluating a multivalued attribute used elsewhere in the calculation.
RR An attribute reference followed by RR specifies that a single subvalue is to be used repeatedly when evaluating a subvalued attribute used elsewhere in the calculation.
Note: Refer to MultiValues for details of how to use R and RR.
To reference attribute 6, enter
A;6
To reference the item-size, enter
A;9999
An attribute defined in the same dictionary can be specified by name through the N function. The processor returns whatever value is generated by the named attribute. If the attribute has attribute 8 codes, they are processed before the value is returned.
N(attribute-name){R{R}}
If the data definition item of the specified attribute contains attribute 8 codes, these are applied before the values(s) are returned.
These codes may also contain an A code function that references another attribute, and so on. For example, if attribute 8 of dictionary item SVRPT contains
A;1 + 2R
and
attribute 8 of dictionary item NEST contains A;N(SVRPT)
, the result of
listing item NEST will be the same as listing item SVRPT.
This nesting capability is an important advantage provided only by the A and F codes.
R An attribute reference followed by R specifies that a single value is to be used repeatedly when evaluating a multivalued attribute used elsewhere in the calculation.
RR An attribute reference followed by RR specifies that a single subvalue is to be used repeatedly when evaluating a subvalued attribute used elsewhere in the calculation.
Note: Refer to MultiValues for details of how to use R and RR.
In the following the value of QTY is the result of processing any codes in attribute 8 of the QTY data definition item:
A;N(QTY)
You can specify a literal string or numeric constant by enclosing it in single or double quotes.
"literal" or 'literal'
Note: A numeric constant not enclosed in double quotes is assumed to be an attribute number.
In the following, "20" is a numeric constant:
A;"20"+N(QTY)
In the following, the number 20 means use the contents of attribute 20 of the current item. It is not a literal:
A;20+N(QTY)
You can use certain mnemonics to reference system parameters like date, time, the current break level, or the number of the current item.
{-}special-operand
The following special operands return the current values of system parameters:
D System date (internal format)
LPV Previous value transformed by a format code
NA Number of attributes
NB Current break level counter:
1 = lowest break level
255 = GRAND-TOTAL line
ND Number of items (detail lines) since the last control break
NF The file specifier in the format:
{DICT }{/account/}file-name{,section-name}
NFA The account name part (if any) of the entered file specifier, in the format:
/account/
If no account was entered, a null string is returned.
NFD The string "DICT " if a dictionary access; otherwise a null string.
NFF The entered file specifier in the format:
{/account/}file-name
That is, with the DICT and section name strings, if any, removed.
NFN The file name part of the entered file specifier - that is, with the DICT, account name and section name strings, if any, removed.
NFS The section name part of the entered file specifier, in the format:
,section-name
If no section name was entered, a null string is returned.
NI Item counter.
NL Item length.
NS Subvalue counter.
NU Date of last update.
NV Value counter.
T System time (internal format).
V Previous value transformed by a format code.
To change the default sign (+) of the value, enter a minus sign before the operand.
Returns the integer portion of a number.
I(expression)
expression An expression that evaluates to a numeric value.
In the following example, the Integer Function returns only the integer part of the value returned by the expression shown:
A;I(N(COST)+N(PI)/N(MC))
Takes two numbers as operands and returns the remainder of the first divided by the second.
R(exp1,exp2)
exp1,exp2 Expressions that evaluate to numeric values.
In the following example, the value returned by attribute COST is divided by 5 and the result is the remainder:
A;R(N(COST),"5")
Evaluates an expression and then adds together all the values.
S(expression)
expression An expression that evaluates to a multivalued list of numeric values.
In the following example, the values returned by attribute HOURS are multiplied by the single value returned by RATE, which is repeated for each value. The multivalued results are then summed:
S(N(RATE)R*N(HOURS))
Extracts a specified number of characters from a string, starting at a specified character.
[start-char-number,number-of-chars]
start-char-number
An expression that evaluates to
the number of the first character of the substring.
number-of-chars An expression that evaluates to the number of characters in the substring.
In the following example, a string of 5 characters starting at the second position is returned:
A;N(NAME)["2","5"]
In the following example, a string can only be retrieved if the starting position is found in attribute 2 and the length in attribute 5:
A;N(NAME)[2,5]
Returns one of two values, depending on the value of a condition.
@(expression, value1, value2)
condition An expression that evaluates to true or false.
value1, value2 Expressions, the results of which are returned depending on the value of condition.
In the following example, the string "True" is returned if the contents of attribute 1 evaluates to true; otherwise, the string “False” is returned.
@(1, "True", "False")
You can follow an A code operand with one or more format codes enclosed in parentheses to convert values stored in internal format to an output format.
operand(format-code{]format-code}...)
operand is one of the A Code operands.
format-code is one of the format codes described in this topic (any code except A, AE, D1, D2, F, FE, FS or U).
] represents the value mark (CTRL+]) that must separate the format-codes.
Using a format code within an A code is different from using a format code following an A code. In the latter case, the processor applies the format code to the result of the A code processing.
To convert the value stored in 'PRICE' to an integer and eliminate the cents, use:
A3;N(PRICE)(MD3]G0.1)*N(QTY)
In this example, both the format codes MD3 and G0.1 are applied only to the value of the attribute PRICE. The result is then multiplied by the value of QTY.
An integer can be output with the embedded decimal point by following the A code with a format code as follows:
A3;N(PRICE)(MD3)*N(QTY)]MD3
where ]MD3
at the end of the A code statement is the format
code.
In this example, the format code MD3 is applied twice: once to the value returned by attribute PRICE; and then to the the complete result after multiplying by the value of QTY.
The IF statement gives the A code conditional capabilities.
IF conditional_expression THEN expression ELSE expression
conditional_expression
must evaluate to true or false.
If true, execute the THEN statement.
If false, execute the ELSE statement.
expression is a string, numeric value or an expression which evaluates to a string or numeric value.
Each IF statement must have a THEN clause and a corresponding ELSE clause.
IF statements can be nested but the result of the statement must evaluate to a single value.
The words IF, THEN, ELSE, AND, and OR must be followed by at least one space.
OR is the default operation and need not be entered.
The following statement
IF 1 THEN IF 2 THEN 3 ELSE 4 ELSE 5
presented structurally would be
IF 1 THEN IF 2 THEN 3 ELSE 4 ELSE 5
In the following example, "VALID" is output if both parts of the IF statement are true. "NO COMMENT" is output if only one part is true or both are false.
A;IF N(OBJ)="4" AND N(PRED)="7" THEN "VALID" ELSE "NO COMMENT"
One of the most powerful features of the A and AE codes is that they can handle multivalues. They normally combine multivalues one-by-one, but if you specify R or RR after an AMC, they repeat the first value and combine it with several multivalues.
Note: The F and FS codes handle multivalues in the same way as the A and AE codes. In the examples below, the equivalent F/FS syntax is shown in parentheses.
Attribute operands may be valued and subvalued. When mathematical operations are performed on two multivalued lists (vectors), the result is also multivalued. The result has as many values as the longer of the two lists. Zeros are substituted for null and missing values in the shorter list.
For example, if attributes 10 and 15 contain the following values:
010 5]10]15 015 20]30]40]50
and the data definition item contains the following code in attribute 8:
A;10+15; (or F;10;15;+;)
when the A code is processed, each value is added to the corresponding value in the other attribute. The result is therefore:
:LIST TEST VALUES TEST...... Values..... THING 25 (5 + 20) 40 (10 + 30) 55 (15 + 40) 50 (0 + 50) ONE ITEM LISTED
To repeat a value for combination with multivalues, follow the AMC with the R operator.
Attributes 10 and 20 of item THING contain:
010 1]2 020 3
Data definition item VALUES has the following code in attribute 8:
A;10 + 20R; (or F;10;20R;+)
The expression repeats the value in attribute 20 to match the number of values in attribute 10:
1]2
3 3 Repeated by the R
The two lists are then added and result in the following:
:LIST TEST VALUES TEST...... Values..... THING 4 (1 + 3) 5 (2 + 3) ONE ITEM LISTED
Note: If the attribute to which the repeat character is applied is mutlivalued, the first value is repeated, but is only used for values in the other attribute for which there is no corresponding value. For example, if attributes 10 and 20 contain the following:
010 1]2]3]4]5]6 020 10]20]]40
and data definition item has the following code in attribute 8:
A;10 + 20R (or F;10;20R;+)
the expression repeats the first value in attribute 20 (that is, 10) to match values in attribute 10 for which there is no value in attribute 20:
1] 2] 3] 4] 5] 6 10 20 0 40 10 10
Note that the first value is only repeated for the missing values – in this case, values 5 and 6. The null in value 3 is treated as 0.
When the two lists are added the following is the result:
:LIST TEST VALUES TEST...... Values..... THING 11 (1 + 10) 22 (2 + 20) 3 (3 + 0) 44 (4 + 40) 15 (5 + 10) 16 (6 + 10) ONE ITEM LISTED
To repeat a value for combination with subvalues, follow the AMC with the RR operator.
Attributes 5 and 20 of item THING contain:
005 1]2\5\7]2\2\9 020 3
Data definition item SUBVALS has the following code in attribute 8:
A;5 + 20RR (or F;5;20RR;+;)
The expression repeats the value in attribute 20 to match the number of subvalues in attribute 5:
1]2\5\7]2\2\9 3 3 3 3 3 3 3
The two lists are then added and result in the following:
:LIST TEST SUBVALS TEST...... Subval...... THING 4 (1 + 3 - Valid subvalue = 3) 6 (2 + 4 - Valid subvalue = 4) 9 (5 + 4 - No subvalue; use subvalue 1 of this value = 4) 11 (7 + 4 - No subvalue; use subvalue 1 of this value = 4) 5 (2 + 3 - No value; use value 1 subvalue 1 = 3) 5 (2 + 3 - No value; use value 1 subvalue 1 = 3) 12 (9 + 3 - No value; use value 1 subvalue 1 = 3) ONE ITEM LISTED
Note the difference between this and a single R character used with
sub-valued data. With a single R character, the repeated value is used only
with the first sub-value in each value. Applying the conversion code A;5 + 20R
(or F;5;20R;+;
) to the same
data therefore results in:
:LIST TEST SUBVALS TEST...... Subval...... THING 4 (1 + 3) 5 (2 + 4) 5 (5 + 0) 7 (7 + 0) 5 (2 + 3) 2 (2 + 0) 9 (9 + 0) ONE ITEM LISTED
Assume a STOCK file with:
Each data item contains:
The dictionary has data definition items PRICE, QTY.A, QTY.B, a total quantity QTY, and VALUE. QTY adds QTY.A and QTY.B; VALUE multiplies QTY by PRICE.
The definition items are as follows:
VALUE PRICE QTY 001 A A A 002 0 l 0 003 Value Price Qty 004 005 006 007 MD2.$ MD2.$ 008 A;N(PRICE)*N(QTY) A;N(QTY.A)+N(QTY.B) 009 R R R 010 10 10 5 QTY.A QTY.B 001 A A 002 2 3 003 Qty.A Qty.B 004 005 006 007 008 009 R R 010 5 5
Data Items are as follows:
1125 1126 1127 1128 001 1269 157 2763 21165 002 12 0 3 5 003 6 9 17 2 . . .
:LIST STOCK QTY.A QTY.B QTY PRICE VALUE PAGE 1 STOCK Qty.A Qty.B Qty.. Price..... Value..... 1125 12 6 18 $12.69 $228.42 1128 5 2 7 $211.65 $1,481.55 1126 0 9 9 $1.57 $14.13 1127 3 17 20 $27.63 $552.60 4 ITEMS LISTED