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 the variant with THEN and
UNTIL, the sequence is defined by the distance between the data objects
dobj1 and dobj2. At all storage locations whose
distances to dobj1 are multiple values of this distance - up to and including the position dobj -,
numeric data objects of identical
type must be stored. The content of all these data objects is added. In the variant with
TO, the total is added to the content of data object result
and the result is assigned to it. In the variant with GIVING,
the total is directly assigned to the data object result.
The data object result must be a numeric variable. If
you use addition ACCORDING, a data object of the sequence is added to the total only if its position in the sequence fulfills the condition in the
selection table
sel. For the components low and
high of the selection table, the data type i is expected.
-
In the variant with TO and
FROM, the sequence is formed by data objects directly adjacent in the storage, whose first
data object is dobj and which must all have the same numeric
data type. For pos1 and pos,
data objects of type i are expected, whose values define
a subset of the sequence. The contents of the data objects of the subsequence are added and assigned
to the data object result. The data object
result must be a numeric variable. If pos1
or pos contain negative values or if
pos1 is greater than pos, the statement is not executed and result remains unchanged.
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
-
The function of these variants of the ADD statement depends
on the structure of the working memory. They are not allowed in classes and can be replaced as required
by the statement ASSIGN with the addition INCREMENT.
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.
Catchable Exceptions
CX_SY_ARITHMETIC_OVERFLOW
-
Cause: Overflow while adding, type I in additions
UNTIL or FROM ... TO
Runtime Error: ADDF_INT_OVERFLOW (catchable)
-
Cause: Overflow during arithmetic operation (type P)
Runtime Error: BCD_OVERFLOW (catchable)
-
Cause: Integer overflow while adding
Runtime Error: COMPUTE_INT_PLUS_OVERFLOW (catchable)
CX_SY_CONVERSION_OVERFLOW
-
Cause: Overflow during arithmetic operation (type P, with specified length)
Runtime Error: BCD_FIELD_OVERFLOW (catchable)
Non-Catchable Exceptions
-
Cause: Access to data outside of the area specified in the RANGE addition
Runtime Error: ADD_FIELDS_NOT_IN_RANGE
-
Cause: Unallowed access to tables, strings, field, or object
references within the area specified by the addition RANGE.
Runtime Error: ADD_FIELDS_ILLEGAL_ACCESS
-
Cause: P field does not contain a correct BCD format
Runtime Error: BCD_BADDATA