Subject: ARMRCALC06
The Calc Brackets
The final operation in a given VPC cycle is the CALC operation. Any number of calc brackets may be coded in this final portion of the VPC cycle. The calc brackets have the following general format:
calc_start= sublist(s) |
      Blitz like calc program |
calc_end= |
On the calc bracket's calc_start= statement you define the sublist(s) to which the bracket's calc program is to be applied. If you omit the sublist specification, ARMRCALC will process all lines of the current data base (default)!
In the following example we move a single value from a field called tally into the following four fields:
sched |
compl |
delinq |
delinqnt |
The destination of tally depends on a combination field values. The tally field's exact destinations are worked out in the prune bracket.
The pruning bracket together with the calc brackets are as follows:
;------------------------------------------------------- ; define sched compl & delinq for all but ENG ;------------------------------------------------------- ; ; select a columnar view by tally in order to streamline ; columns= tally ; ; define three sets: 1-complete 2-delinquent 3-active ; for the delinquents define subset: nontalk ; prune_start= ; ; records with org="ENG" are not to be processed in this VPC ; bracket_start= field= org value= ENG leftover= noteng bracket_end= ; ; records with wkdelq=D belong to the delinquent set ; bracket_start= noteng field= wkdelq value= D match= delinquent leftover= nondelq bracket_end= ; ; non-delinquents whose completion date is nonzero are complete ; the remainders are still active ; bracket_start= nondelq field= comp value= 0 match= active leftover= complete bracket_end= ; ; active records which have been cancelled (st=CN) are ignored ; bracket_start= active field= st value= CN leftover= active match= tonydelete bracket_end= ; ; some of the delinquent records are "non-talkable" ; the latter have mv=N or R ; bracket_start= input= delinquent field= mv value= N R match= nontalk bracket_end= prune_end= ; ; set the four destination fields to zero initially ; calc_start= noteng sched=0 compl=0 delinq=0 delinqnt=0 calc_end= ; ; set schedule quantity for all subsets ; calc_start= complete delinquent active sched=tally calc_end= ; ; set completions ; calc_start= complete compl=tally calc_end= ; ; set delinquents ; calc_start= delinquent delinq=tally calc_end= ; ; a subset of the delinquent set is also non-talkable ; calc_start= nontalk delinqnt=tally calc_end= end=
ARMRCALC is very flexible when it comes to subset definitions. The sets "delinquent" and "nontalk" shown above are not mutually exclusive. In fact, "nontalk" is a subset of "delinquent".
+ addition |
- subtraction |
* multiplication |
/ division |
= moves source expression to target symbol |
symbols
      + - * / = , ( )
constants
Expressions
An expression appears to the right of an equal sign; i.e.
symbol= expression.
Standard preference hierarchy applies with regard to the arithmetic operators. You may use left and right parenthesis to insure the desired calculation sequences; e.g. if you want x to be set to the sum of A and B over C plus D write:
      x=(A+B)/(C+D) Without parenthesis you would need at least two lines to generate the equivalent result; i.e. you might write:
      denom=C+D
      x=A/denom+D/denom
You may nest parenthesized structures to any desired level.
A calc line contains one expression. We do not currently support continuation lines.
The calc compiler will remove all extraneous blanks from your calc line. The compact calc line may be up to 80 characters in length.
If an expression is too long for your line space, you need to break down the expression. To do so, introduce intermediate symbols.
Note ARMRCALC will store values in the data base for all expressions in which a field name appears to the left of the equal sign.
Functions described in detail later. Their general structure is as follows:
      function_name(arg1,arg2,arg3, ... )
arg1,arg2,arg3, ... are input arguments. Arguments are symbols, constants, or expressions.
Functions return a single value; e.g.
      x=sqrt(y)
The sqrt function computes the square root of y. The result is stored in x. The following expression returns the 4th root of y:
      x=sqrt(sqrt(y))
ARMRCALC's case sensitivity was described earlier. You may use lower case, upper case, or a mixture of the two. Internally, ARMRCALC will convert everything to lower case. An exception to this rule is the literal string equate statement; e.g. in the following statement, the string enclosed in quotes is not translated:
      x="This is not translated."
ARMRCALC's compiler is designed to manipulate numbers; i.e. when you use field names as operands it is understood that we deal with the numbers which are stored in the ARMR data base; e.g. assume x and y are field names. The statement
      x=y
moves the number stored in x into y. This simple equate may not always yield the desired results. In particular, do not use the above form under the following conditions:
Data moves for conditions c) and d) are not supported at all with ARMRCALC.
Two special operations are supported which allow you to move strings into a data base fields. These are as follows:
Literal Move
The literal move statement has the following form:
x=" alpha-numeric string "
x is assumed to be a tabular or an EBCDIC data base field name.
The string to be moved to x appears between the leading and the trailing quote marks. ARMRCALC scans for leading and trailing " (quote mark). Any other quote marks are ignored; i.e. the textual string may contain any number of quote marks. All but leading an trailing quotes are considered to be part of the string to be moved.
ARMRCALC will take an error exit if any non-blank data appears to the right of the trailing quote! Moreover, we insists that the literal string is not longer than the target fields display width.
A sample of literal equate is as follows:
calc_start= 777ATR fname="777ATR" LNGTYP= "TRANSITION" calc_end=
Field Copy
The field copy statement has the following format:
      x=string(y)
Source and target (y & x) are assumed to be of the same data type with identical display width.
Note if x and y are tabular fields sharing the same table, use the simpler x=y form!
Do not think of the field copy statement as a calc function. Although it has a function format it lacks other important properties; i.e. the string(y) can not be embedded in a general calc expression. It only makes sense when used as shown above.
The calc bracket's lines are normally executed once for each data term in the order defined by the given data view. The significance of the data view was described earlier. The order of processing becomes important when you use the "next" or the "previous" function!
See "The View Operation" above for more information. There we have included a calc example.
Note: There are a few functions for which we do not execute once for each data term; i.e. when a calc bracket contains a call to the functions: arcgen, split, or mend we execute the bracket in a single step. This should not worry you too much, except that those special functions should always be the only statement in a given calc bracket. See individual writeups of those functions for more detail.
A number of important functions are supported by ARMRCALC. These are described in separate documents.