Assigning to a Variable Occurrence

It may happen that in a QAB program we need to be able to assign a value to the nth occurence of some field, where n is a variable. This type of prcessing is very awkward in QAB. It may sometimes be possible to use some kind of trick to change the field - the PROVIDED operator is sometimes useful for this. However the most general method is to use the | operator and the HEAD and TAIL functions.

To assign a single value to a multi-occurs numeric field:

  1. Add the multi-occurs field to the field processing list (see Field Editing) and in the Field Details, set low occurs to 1 and high occurs to the number of occurrences in the field.
  2. Add a formula which uses a combination of the head() and tail() operators.

    For example, to assign to the ith occurrence of the N10*12 budget field you could use something like this :
    head(budget,i-1)| new_value | tail(budget, 12-i)

To assign to n adjacent occurrences you can extend the same technique as follows:

head(budget,i-1)| new_value_1 | new_value_2 |...| new_value_n | tail(budget, 12-i-(n-1))