F Correlative

Stack Functions. The F correlative performs mathematical and string processing operations on specified attributes or constants.

The F correlative is made up of operands and operators in reverse Polish format separated by semicolons.

Format

F [;] element [; element ;…]

The INFO/ACCESS program processes the F code from left to right, putting each element on the stack as an operand until it encounters an operator. The semicolon is used to separate elements. An element can be any of the following:

Attributes

An attribute can be referenced only by its attribute number.

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.

Literals

Any literal string must be enclosed within single or double quotes. A numeric constant, which can be any positive or negative integer or zero, must either be enclosed within single or double quotes or be preceded by a C, thus:

Cn

 

n

Numeric constant to be pushed onto the stack

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 for 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

_

Exchanges the first and second elements in the stack.

:

Concatenates the first element in the stack to the end of the second element.

^

Pops (removes) the first element off the stack.

P

Duplicates the first element and pushes it onto the stack.

R

Divides the first element in the stack by the second element, putting the remainder on top.

S

Sums all values in the first element of stack 1.

[]

Extracts a substring. This function uses the top three elements in the stack, where:

1 ‰ length

2 ‰ start

3 ‰ string

The third element on the stack is the string to be operated on. The second element is the character position at which extraction starts. The first element is the number of characters to extract. The result is placed on top of the stack.

(conversion code)

Applies a conversion on the first element in the stack.

Arithmetic Operators

These arithmetic operators work on the top two elements in the stack. The operands are popped and the result is pushed on to the stack as the first element. Arithmetic operations are carried out on integers only; any decimal places are disregarded. Nonnumerics are treated as zeroes and no error message is displayed.

+

Adds the first and second elements in the stack.

-

Subtracts the first element from the second element.

*[n ]

Multiplies the first and second elements. The optional n is the descaling factor, that is, the result is divided by 10 raised to the nth power.

/

Divides the second element by the first element.

Relational Operators

These 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 whether the condition is or is not satisfied:

=

Equal to

#

Not equal to

>

Greater than

<

Less than

<= or [

Less than or equal to

>= or ]

Greater than or equal to

Using the F Correlative

In this example, a simple F correlative returns the product of two attributes which contain the quantity ordered and the price per item:

F ; 2 ; 3 ; *

The contents of Attributes 2 and 3 are placed on the stack. The multiplication operator pops these two elements and pushes the result on top of the stack.

The next example computes a 5% tax for the amount of the order:

F ; 2 ; 3 ; * ; C 5 ; * ; (MR2$)

The result of multiplying Attributes 2 and 3 is multiplied by the constant 5. A masked decimal conversion is applied to the result.

If Attributes 2 and 3 in the above example are MultiValued, the S function can be used to accumulate the amount of the order before figuring out the tax. This correlative provides the total tax for MultiValued attributes:

F ; 2 ; 3 ; * ; S ; C 5 ; * ; (MR2)

In the next example, a file translation correlative (see the TFILE correlative) is applied in an F correlative to obtain the amount of a sale. Then a 10% discount is calculated and subtracted from that amount:

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

The first action is to place Attribute 1 on the stack and use it to reference items in the ORDERS file and retrieve the third attribute. This gives the amount of a sale. That amount is duplicated by pushing a copy of it on top of the stack and then apply a masked decimal conversion. The exchange function “_” is used to swap the converted result with the unconverted duplicate. The constant 10 is placed on the stack. The multiplication operator pops the top two elements (the amount of the sale, and 10) and places this result, which is the amount of the discount, on the top. Next, a conversion is applied to that result, and then the converted discount is subtracted from the converted amount of sale. A conversion is applied to the final result.

This example returns the number of years’ difference between today’s date and a date in Attribute 3:

F ; D ; (DY) ; 3 ; (DY) ;  –

The system variable D provides today’s date; the conversion DY is applied to it, pushing the current year on the stack. Attribute 3 provides a stored date and the same conversion is applied to it. When the subtraction operator is applied, the current year is the second element in the stack and the referenced year is the first element.

See Also

Correlatives and Conversions Reference