A Correlative

Arithmetic and String Functions. The A correlative is used to perform arithmetic or string processing. It can be used to manipulate numeric or string data located in other attributes. The A correlative is an easier-to-use version of the F correlative.

Format

A [;] expression

Parameter(s)

expression

One or more arithmetic or relational operators which operate on any of the following operands:

attributes

Specified either by attribute number or by dictionary name.

literals

In single or double quotes.

system variables

 

functions

 

parentheses

May be used to indicate the precedence of operations.

Description

All of these expressions are described in more detail in the following sections.

Attributes

An attribute is identified by its attribute number or by its dictionary name. When a dictionary name is specified, correlatives and conversions, if present, are applied before the data element is used in expression. This may require that you mask decimals with scaling (see ML and MR Conversions).
 

attribute#[R]

Attribute number that refers to the position of data in the file. An optional R code can be used with MultiValued attributes to specify that the first value or subvalue of an attribute is to be used repeatedly in an operation involving other MultiValued attributes.

N(name)

Attribute name as defined in the dictionary. If the name is not found, an error message is returned.

9998

Current item count.

9999

Current item size.

Literals

A literal, either a string or a numeric constant, must be enclosed in single or double quotes. A numeric value can be any positive or negative integer, or zero.

System Variables

These system variables are available as operands in any expression:

D

Indicates the system date in internal format.

LPV

Means load previous value; that is, load the result of the last correlative or conversion for further processing.

NB

A break level counter, incremented with each break that is encountered. The lowest-level break is 1; the break that specifies the grand total is 255.

ND

A detail line counter. This supplies the total number of detail lines at each breakpoint.

NI

An item counter, incremented for each item in an output list.

NS

A subvalue counter, incremented for each subvalue of an attribute.

NV

A value counter, incremented for each value in a MultiValued attribute.

T

Indicates the system time in internal format.

Functions

R(operand1, operand2)

The remainder (or modulo) after dividing the first operand by the second operand. An operand can be any valid expression.

S(expression)

Sums all MultiValues in expression.

attribute [start,length]

Extracts a substring. attribute can be identified by attribute number or by dictionary name. Attribute numbers, literals in single or double quotes, or expressions can be specified within the brackets. Brackets are part of the syntax here and must be typed. start is the starting position of the first character to be extracted, length is the number of characters to be extracted.

IF expression1 THEN expression2 ELSE expression3

A conditional statement that evaluates expression1 and, if true, then evaluates expression2, or if false, evaluates expression3.

Arithmetic Operators

+

Addition

-

Subtraction

*

Multiplication

/

Division (returns an integer)

Relational Operators

=

Equal to

#

Not equal to

>

Greater than

<

Less than

>=

Greater than or equal to

<=

Less than or equal to

Precedence of Operations

The precedence of operations is:

  1. Multiplication and division

  2. Addition and subtraction

  3. Relational operations

If two operators have the same precedence, they are evaluated from left to right. Use parentheses to specify the order for evaluating each operation; up to 20 nested levels of parentheses are permitted.

Using the A Correlative

The following A correlative calculates the amount of sale for a given book in an order. This is done by multiplying Attribute 2 (the number of copies sold) by the data in the attribute PRICE. A masked decimal conversion is applied to the result:

   AMOUNT

001 S

002 0

003

004

005

006

007 MR2$

008 A ; 2*N(PRICE)

009 R

010 10

The next A correlative calculates the total sale for an order (consisting of multiple copies of more than one book) by summing the totals calculated for the MultiValued attribute AMOUNT. Again, a masked decimal conversion is applied to the result:

   TOTAL.AMT

001 S

002 0

003 TOTAL

004

005

006

007 MR2$

008 A ; S(N(AMOUNT))

009 R

010 10

The table below shows more examples of how the A correlative is used:

A Correlative

What it does

A ; 1+2

Adds Attributes 1 and 2.

A ; "10"*3

Multiplies each value of Attribute 3 by 10.

A ; S(4+"25")

Adds 25 to each value of Attribute 4, then sums the MultiValues.

A ; N(INV-AMT)-N(BAL-DUE)

Subtracts the value of the attribute BAL-DUE from the value of the attribute INV-AMT.

A ; N(SS-NUM)['4','2']

Returns the fourth and fifth digits of the attribute SS-NUM.

See Also

Correlatives and Conversions Reference