Fri Jan 22 1999

ARMRCALC

Subject: ARMRCALC07

Function: previous(y)


x=previous(y)
x=prev(y)

Purpose

The prev function is basically a sequencing function. Keep in mind that we apply the calc program to the viewed data base in top-down sequence. The previous function lets you address the line immediately above the current line being processed; i.e. prev lets you look at the output from the previous calc pass.

The previous of the very first line on any page is always 0; i.e. the first line on a page has no previous columnar line as far as the current function is concerned.

Example

The following expression generates sequence numbers and stores them in a field called seq:

      seq=prev(seq)+1

The process is shown in the following sketch:

             input                            output
             -----                            ------
              seq        prev(seq)    +1       seq
              ---        ---------   ----      ---
      line1    ?             0        +1  =     1
      line2    ?             1        +1  =     2
      line3    ?             2        +1  =     3
      line4    ?             3        +1  =     4
      line4    ?             4        +1  =     5

Note

prev looks at the output column! prev of line1 =0.

The previous function has other important applications; e.g. use prev to generate running totals like this:

      balance=prev(balance)+deposit+interest-withdrawl

Another example of the prev function involves removing blanks by propagating a textual value. Assume that text is a tabular field. The seq field has values as shown; i.e. the seq field keeps the data records in proper sequence. The following expression yields the desired propagation:

            text=max(prev(text),text)

       input        tabular index values       output
      ----------    ---------------------     --------
      seq   text    prev(text)  text  max        text
      ---   ----    ----------  ----  ---        ----
       1     A          0        1  =  1     =    A
       2                1        0  =  1     =    A          text
       3                1        0  =  1     =    A    index table
       4     B          1        2  =  2     =    B    ----- -----
       5                2        0  =  2     =    B      1     A
       6     C          2        3  =  3     =    C      2     B
       7                3        0  =  3     =    C      3     C
       8                3        0  =  3     =    C      4     D
       9     D          3        4  =  4     =    D
      10                4        0  =  4     =    D

Note

prev looks at the output column! "text" is taken from the input column! Tabular values are stored as binary integers in the data base. The integers represent tabular index values.

The max is a function which returns the maximum of two values. The max function is documented later on.