A Code

Manipulating Numeric Data and Strings. The A code is used to manipulate literals, system variables, and numeric or string data located in other attributes.

Format

A [;]expression

Parameter(s)

expression

Can be one or more arithmetic or relational operators which operate on any of these operands:

attributes

Specified either by attribute number (AMC) or by attribute name.

literals

Appear in single or double quotes .

system variables

 

functions

 

Description

Use parentheses to indicate the precedence of operations. A maximum of 20 levels of nesting parentheses are permitted with the A code. If parentheses are not used, the order of precedence of operations is:

  1. Multiplication and division

  2. Addition and subtraction

  3. Relational operators

If two operators have the same precedence, they are applied from left to right.

The next command line demonstrates how to apply a simple A correlative. A book store’s ORDERS file contains the A correlative to calculate the total amount of sale for any title ordered:

A ; 2 * N (PRICE)

This correlative multiplies the data stored in Attribute 2 (the number of copies sold) by the data from the attribute PRICE. The illustration below identifies each element in this correlative code.

In this figure, Attribute 2, QTY, is referenced by its attribute number (2), but the attribute PRICE is referenced by its attribute name. When referencing an attribute by its number, or AMC, just the number itself is needed. When referencing an attribute by its name, however, the name must be enclosed in parentheses and preceded by the letter N. INFO/ACCESS handles the data stored in these two attributes differently because of how they are referenced.

If you specify an attribute by its attribute number, the values in that attribute position are used just as they are stored. If, however, you specify the attribute by its attribute name (the item-ID of the Attribute Definition item in the file dictionary), any correlatives are applied before processing.

In the figure above, Attribute 2 is referenced by its attribute number because the data is stored in attribute position 2 in the file. The attribute PRICE, however, is referenced not by its number but by its name, because its data is not stored in the ORDERS file at all but is derived from the BOOK-CATALOG file. Price data is obtained from the BOOK-CATALOG file using a TFILE correlative. The TFILE correlative is located in the ORDERS dictionary, in the Attribute Definition item for PRICE. (TFILE correlatives are described in detail later in this section.)

When attribute names are specified, they must be enclosed in parentheses and preceded by the letter N, as shown in the next example.

The Attribute Definition item for the attribute AMOUNT contains the following data:

  AMOUNT

001  S

002  0

003

004

005

006

007  MR2$

008  A ; 2*N(PRICE)

009  R

010  10

The attribute number shown for AMOUNT is 0. This is because the data is derived, not stored in the file in a specified attribute position. Since the Attribute Definition item for AMOUNT does not define a real attribute (that is, one that contains data stored in the file), it is sometimes referred to as a dummy attribute. Any number can be used as the attribute number of a dummy attribute; using high numbers such as 99 or 999 is a frequently seen convention. Do not, however, use 9999, as this is reserved. Further description of the A correlative is featured in other topics of this section.

Constants included in an A correlative must be enclosed in single or double quotes. For example, the A correlative in the next command line multiplies the data in the attribute PRICE by the number 2, not by data contained in Attribute 2:

A ; "2" * N (PRICE)

The A correlative in the next example calculates the total sale for an order (consisting of multiple copies of more than one book):

A ; S (N (AMOUNT))

The S function shown in the preceding correlative sums all of the data in the specified MultiValued attribute (in this case, AMOUNT).

The arithmetic and relational operators that can be used with the A correlative are shown in the table below.

Operator

Meaning

+

Addition

-

Subtraction

*

Multiplication

/

Division (returns an integer)

=

Equal to

#

Not equal to

>

Greater than

<

Less than

>=

Greater than or equal to

<=

Less than or equal to

You can also use the boolean operators AND and OR. You cannot use & (and) or ! (or).

System functions that may be used with the A correlative are shown in the table below.

Function

Operation

R

Returns the remainder after division.

S

Sums MultiValues.

[]

Extracts a substring.

IF/THEN/ELSE

Used in conditional expression.

The following topics are also presented in this section:

R Function

S Function

[ ] Function

IF/THEN/ELSE

Special System Functions

See Also

Performing Arithmetic Operations

F Code