Variants:

1. ADD n TO m.

2. ADD n1 THEN n2 UNTIL nz GIVING m.

3. ADD n1 THEN n2 UNTIL nz TO m.

4. ADD n1 THEN n2 UNTIL nz

...ACCORDING TO sel ...GIVING m.

5. ADD n1 FROM m1 TO mz GIVING m.

Effect

Adds the contents of n to the contents of m and stores the
result in m.

This is equivalent to: `m = m + n.`

Example

DATA: NUMBER TYPE I VALUE 3, SUM TYPE I VALUE 5. ADD NUMBER TO SUM.

The field `SUM` now contains the value 8, whilst the
contents of the field `NUMBER` remains unchanged at 3.

Note

The details about conversions and performance described under
**
COMPUTE** are identical for ADD .

- BCD_FIELD_OVERFLOW: Result field too small (type P).

- BCD_OVERFLOW: Overflow with arithmetic operation (type P)

- COMPUTE_INT_PLUS_OVERFLOW: Integer overflow when adding.

**Non-catchable runtime error**

- BCD_BADDATA: P field does not contain correct BCD format.

Related

Effect

Adds the contents of the fields n1, n2, ..., nz together and
stores the result in m, where n1 is the first, n2 the second and nz
the last of a sequence of fields the same distance apart. They can
be either database fields or internal fields, but they must all
have the same type and length.

This is equivalent to: `m = n1 + n2 + ... + nz.`

Example

DATA: BEGIN OF NUMBERS, ONE TYPE P VALUE 10, TWO TYPE P VALUE 20, THREE TYPE P VALUE 30, FOUR TYPE P VALUE 40, FIVE TYPE P VALUE 50, SIX TYPE P VALUE 60, END OF NUMBERS, SUM TYPE I VALUE 1000. ADD NUMBERS-ONE THEN NUMBERS-TWO UNTIL NUMBERS-FIVE GIVING SUM.

The field `SUM` now contains 150 but its initial value is
unimportant. The fields within the structure `NUMBERS`
remain unchanged.

Effect

Calculates the total as in variant 2 but then adds it to the
contents of the field m.

This is equivalent to: `m = m + n1 + n2 + ... + nz`

Example

DATA: BEGIN OF NUMBERS, ONE TYPE P VALUE 10, TWO TYPE P VALUE 20, THREE TYPE P VALUE 30, FOUR TYPE P VALUE 40, FIVE TYPE P VALUE 50, END OF NUMBERS, SUM TYPE I VALUE 1000. ADD NUMBERS-ONE THEN NUMBERS-TWO UNTIL NUMBERS-FIVE TO SUM.

The field `SUM` now contains 1150.

**Variant 4**

ADD n1 THEN n2 UNTIL nz

...ACCORDING TO sel ...GIVING m.

Parts marked with " ..." are interchangeable

Effect

Calculates the total as in variants 2 and 3. In this case,
however, the operands from a sequence of fields of the same type
are restricted to a partial sequence by the selection specification
sel generated by ** SELECT-OPTIONS**
or

Example

DATA: BEGIN OF NUMBERS, ONE TYPE P VALUE 10, TWO TYPE P VALUE 20, THREE TYPE P VALUE 30, FOUR TYPE P VALUE 40, FIVE TYPE P VALUE 50, END OF NUMBERS, SUM TYPE I VALUE 1000, INDEX TYPE I. RANGES SELECTION FOR INDEX. SELECTION-SIGN = 'I'. SELECTION-OPTION = 'BT'. SELECTION-LOW = 2. SELECTION-HIGH = 4. APPEND SELECTION. ADD NUMBERS-ONE THEN NUMBERS-TWO UNTIL NUMBERS-FIVE ACCORDING TO SELECTION GIVING SUM.

`SUM` now contains 90. Only the sub-fields `TWO`
to `FOUR` were selected from the structure `NUMBERS`
and added together.

Effect

The field n1 must be the first in a sequence of consecutive fields of the same type. m1 and mz should contain the numbers of the first and last fields in this sequence to be added together (whether fixed or variable). The total is stored in m.

Example

DATA: BEGIN OF NUMBERS, ONE TYPE P VALUE 10, TWO TYPE P VALUE 20, THREE TYPE P VALUE 30, FOUR TYPE P VALUE 40, FIVE TYPE P VALUE 50, END OF NUMBERS, START TYPE I VALUE 2, SUM TYPE I VALUE 1000. ADD NUMBERS-ONE FROM START TO 4 GIVING SUM.

The field `SUM` now contains 90.

The details regarding conversions and performance specified for
**
COMPUTE** are equally valid for ADD. However, in
the case of variants 2 to 5, the type of caculation type depends
only on the operands. Integer arithmetic is used if the operand is
type I, floating point arithmetic if the operand is type F, and
packed arithmetic if the operand is type P.

The runtime required for adding two numbers of type I or F is about 2 msn (standardized microseconds), for type P it is roughly 8 msn.

Besides the runtime errors listed in variant 1, other catchable
runtime errors can occur instead of COMPUTE_INT_PLUS_OVERFLOW in
other variants.