ADD - THEN, UNTIL

Short Reference

Syntax

ADD { { dobj1 THEN dobj2 UNTIL dobj
      { {TO result} | {GIVING result [ACCORDING TO sel]} } }
    | { dobj FROM pos1 TO pos GIVING result } }
    [RANGE range].

Effect

This variant of the ADD statement, which is not allowed in classes, adds sequences of data objects that are stored in the memory in equal distances from one another.

In both variants, an untreatable exception occurs if addresses are accessed that do not contain suitable data objects.

In Unicode programs, all data objects of the sequence must lie within one structure. If in the syntax check, this cannot be recognized statically, you must specify a structure range with addition RANGE. If during execution of the statement, the data objects of the sequence are not part of the specified structure, an untreatable exception is triggered.

In non-Unicode programs, the sequence of the data objects can extend over the entire data area of the current program. Only if the first data object of the sequence is specified as a field symbol, the area boundaries defined using the addition range_spec of statement ASSIGN at the same time specify the allowed area of the sequence.

Note

Example

The components of structure numbers specified on the selection screen are added and the total is assigned to variable sum.

DATA: BEGIN OF numbers,
        one   TYPE p LENGTH 8 DECIMALS 0 VALUE 10,
        two   TYPE p LENGTH 8 DECIMALS 0 VALUE 20,
        three TYPE p LENGTH 8 DECIMALS 0 VALUE 30,
        four  TYPE p LENGTH 8 DECIMALS 0 VALUE 40,
        five  TYPE p LENGTH 8 DECIMALS 0 VALUE 50,
      END OF numbers,
      sum     TYPE i.

SELECT-OPTIONS position FOR sum.

ADD numbers-one THEN numbers-two
                UNTIL numbers-five
                ACCORDING TO position
                GIVING sum.

Exceptions

Catchable Exceptions

CX_SY_ARITHMETIC_OVERFLOW

CX_SY_CONVERSION_OVERFLOW

Non-Catchable Exceptions