ABAP Keyword Documentation → ABAP - Reference → Obsolete Language Elements → Obsolete Calculation Statements
ADD - THEN, UNTIL
Other versions: 7.31 | 7.40 | 7.54
Obsolete 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 statement ADD
,
which is not allowed in classes, adds strings of data objects that are stored in equal distances from one another in the memory.
-
In the variant with
THEN
andUNTIL
, the string is defined by the distance between the data objectsdobj1
anddobj2
. At all memory positions whose distances todobj1
are multiple values of this distance (up to and including the positiondobj
), numeric data objects with the same technical type attributes must be stored. The content of all these data objects is added. In the variant withTO
, the total is added to the content of the data objectresult
and the result is assigned to it. In the variant withGIVING
, the total is directly assigned to the data objectresult
. The data objectresult
must be a numeric variable. If the additionACCORDING
is used, a data object of the string is added to the total only if its position in the string fulfills the condition in the selection table sel. The componentslow
andhigh
in the selection table expect the data typei
. -
In the variant with
TO
andFROM
, the string is formed by data objects directly adjacent in the memory, the first data object beingdobj
and all having the same numeric data type.pos1
andpos
expect data objects of the typei
, whose values define a subset of the string. The contents of the data objects of the substring are added and assigned to the data objectresult
. The data objectresult
must be a numeric variable. Ifpos1
orpos
contain negative values or ifpos1
is greater thanpos
, the statement is not executed andresult
remains unchanged.
In both variants, an unhandleable exception is raised if addresses are accessed that do not contain suitable data objects.
All data objects of the string must be within a structure. If this cannot be detected statically in
the syntax check, a structure range
with the addition RANGE
must be specified. If the data objects of the string are not part of the specified structure when the statement is executed, an unhandleable exception is raised.
Note
The function of these variants of the ADD
statement depends on the structure
of the working memory. Memory-based operations of this type should be avoided. They are not allowed
in classes and can be replaced as required by the statement
ASSIGN with the addition INCREMENT
.
Example
The components of the 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
-
Cause: Overflow while adding, type I in additions
UNTIL
orFROM
...TO
Runtime Error:ADDF_INT_OVERFLOW
-
Cause: Overflow in arithmetic operation (type
p
)
Runtime Error:BCD_OVERFLOW
-
Cause: Integer overflow while adding
Runtime Error:COMPUTE_INT_PLUS_OVERFLOW
CX_SY_CONVERSION_OVERFLOW
-
Cause: Overflow in arithmetic operation (type
p
, with specified length)
Runtime Error:BCD_FIELD_OVERFLOW
Non-Catchable Exceptions
-
Cause: Access to data outside of the range specified in the
RANGE
addition
Runtime Error:ADD_FIELDS_NOT_IN_RANGE
-
Cause: Invalid access to tables, strings, field references, or object references within the range specified by the addition
RANGE
.
Runtime Error:ADD_FIELDS_ILLEGAL_ACCESS
-
Cause:
p
field does not contain the correct BCD format
Runtime Error:BCD_BADDATA