DICT

F Correlative

Stack Functions

The F correlative performs mathematical and string processing operations on specified attributes or constants. It comprises operands and operators in reverse Polish format separated by semi-colons.

F[;]element[;element;...]

The program processes the F code from left to right, putting each element on the stack as an operand until it encounters an operator.

The system uses a semi-colon to separate elements. An element can be any of the following:

* attribute number.

* literal.

* system variable.

* function.

* arithmetic operator.

* relational operator.

ATTRIBUTES

You can reference an attribute only by its attribute number.

attribute number that refers to the position of data in the file. You can use an optional R code with multi-valued attributes to specify that the first value or sub-value of an attribute you want to use repeatedly in an operation involving other multi-valued attributes.

LITERALS

You must enclose any literal string or numeric constant within single quotes, double quotes, or backslashes or be preceded by a C, thus:

Cn

where n is a literal string or a numeric constant you want to push onto the stack.

SYSTEM VARIABLES

The following 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 break level counter, incremented each time the system encounters a break. The lowest-level break is 1; the break that specifies the grand total is 255.

ND detail line counter. This supplies the total number of detail lines at each break point.

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

NS sub-value counter, incremented for each sub-value of an attribute.

NV value counter, incremented for each value in a multi-valued attribute.

T indicates the system time in internal format.

FUNCTIONS

- exchanges the 1st and 2nd elements in the stack.

: concatenates the 1st element in the stack to the end of the 2nd element.

^ pops, removes, the 1st element from the stack.

P duplicates the 1st element and pushes it onto the stack.

R divides the 1st element in the stack by the 2nd element, putting the remainder on top.

S sums all values in the 1st element of stack 1.

[] extracts a sub-string. This function uses the top three elements in the stack, where:

The 3rd element on the stack is the string you want to operate on. The 2nd element is the character position at which extraction starts. The 1st element is the number of characters to extract. The system places the result on top of the stack.

applies a conversion on the 1st element in the stack.

ARITHMETIC OPERATORS

The following arithmetic operators work on the top two elements in the stack. The system pops operands and pushes the result on to the stack as the 1st element. It carries out arithmetic operations on integers only; it disregards any decimal places. It treats non-numerics as zeros and does not display an error.

+ adds the 1st and 2nd elements in the stack.

- subtracts the 1st element from the 2nd element.

*[n] multiplies the 1st and 2nd elements. The optional n is the descaling factor, that is, the system divides the result by 10 raised to the nth power.

/ divides the 2nd element by the 1st element.

RELATIONAL OPERATORS

The following operators work on the top two elements in the stack and return a result of one or zero to the top of the stack, depending on the result of the condition:

= equal to.

# not equal to.

> greater than.

< less than.

[ greater than or equal to.

] less than or equal to.

USING THE F CORRELATIVE

F;2;3;*

This F correlative returns the product of two attributes that contain the quantity ordered and the price per item:

The system places the contents of Attribute 2 and 3 on the stack. The multiplication operator pops these two elements and pushes the result on top of the stack.

F;2;3;*;C5;*;(MR2$)

Computes a 5% tax for the amount of the order.

Multiplies the result of multiplying Attributes 2 and 3 by the constant 5 and applies a masked decimal conversion to the result.

If Attributes 2 and 3 in the example are multi-valued, you can use S to accumulate the amount of the order before calculating the tax.

F;2;3;*;S;C5;*;(MR2)

Provides the total tax for multi-valued attributes.

F;1;(TORDERS;X;;3);P;(MR2);_;C10*;3;(MR2);-;(MR2$)

Applies a file translation correlative, refer to Tfile, in an F correlative to obtain the amount of a sale, and calculates a 10% discount and subtracts it from that amount.

The first action is to place Attribute 1 on the stack and use it to reference items in the ORDERS file and retrieve the 3rd attribute. This gives the amount of sale. The system duplicates the amount by pushing a copy on top of the stack, using P and applies a masked decimal conversion. The system uses the exchange function '_' to swap the converted result with the unconverted duplicate. The system places the constant 10 on the stack. The multiplication operator pops the top two elements, the amount of sale and 10, and places this result, which is the amount of discount, on the top of the stack. Next, the system applies a conversion to that result, and subtracts the converted discount from converted amount of sale. The system applies a conversion to the final result.

F;D;(DY);3;(DY);-

Returns the number of years difference between today's date and the date in Attribute 3.

The system variable 'D' provides today's date; the system applies the conversion DY to it, pushing the current year on the stack. Attribute 3 provides a stored date and applies the same conversion. When the system applies the subtraction operator, the current year is the 2nd element in the stack and the referenced year is the 1st element.