SAP EQUALS ARITH EXPR



Get Example source ABAP code based on a different SAP table
  


• = ABAP_ARITH_EXPR

=, Arithmetic Expression

ABAP_SYNTAX
result = arith_exp.

What does it do?
If an arithmetic expression arith_exp is specified on the right side of the assignment operator =, its calculation type is calculated and assigned to the left side result.
The following can be specified for result:
A variable that is compatible with the numeric result of the arithmetic expression or to whose type the result can be converted.
An inline declaration DATA(var) or FINAL(var). The data type of the declared variable var is the statically known calculation type, where generically typed field symbols and formal parameters are part of this calculation type using a standard type described here. In the case of the calculation type p, the data type of the declared variable is always p with the length 8 without decimal places.
If an existing variable is specified for result, its data type is included in the determination of the calculation type. If the calculation type is not the data type of result, the result is converted to the data type of the result field before the assignment is made.



Latest notes:

The fact that the result field is respected when the calculation type is determined is a special property of ABAP that should always be kept in mind.
The calculation type that is dependent on the data type of the result field is an important difference from an assignment of data objects. If data objects are incompatible, the source field is always converted to the data type of the target field. When arithmetic expre ssions are assigned, their operands can also be converted to the data type of the result field before the calculation.
The fact that a calculation type p on the right side of an inline declaration produces the data type p with length 8 and no decimal places can lead to unexpected results and raise exceptions. It is best to either avoid inline declarat ions when using the calculation type p or to determine the data type by applying the conversion operator CONV to the arithmetic expression.
See also calculation assignments with the operators +=, -=, *= and /=.
NON_V5_HINTS
ABAP_HINT_END

ABAP_EXAMPLE_VX5
The first assignment is an assignment of an arithmetic expression, because of the leading plus/minus sign. The calculation type is determined as i and result is given the value 731036, the number of days since 01.01.0001. The second assignment, on the other hand, has the same meaning as an assignment of data objects and produces the value 20020704 in result.
ABEXA 01012
ABAP_EXAMPLE_END

ABAP_EXAMPLE_VX5
This example demonstrates inline declarations with the calculation type p. Assignments of a data object use its data type, but assignments of an arithmetic expression with the calculation type p , the data type p with length 8 and without decimal places is used. This means that decimal places are lost in the first assignment and that the second assignment produces and overflow and its corresponding exception. The conversion operator CONV can be used to avoid these problems.
ABEXA 01013
ABAP_EXAMPLE_END