ABAP Keyword Documentation → ABAP - Reference → Creating Objects and Values
VALUE - Value Operator
Other versions:
7.31 | 7.40 | 7.54
Syntax
... VALUE type( ... ) ...
Effect
A constructor expression with the value operator
VALUE
creates a result of a data type specified using type
. The following can be specified for type
:
- A non-generic data type
type
.
- Exceptions to this rule are:
- The operand can be evaluated after
BASE
when a structure or an internal table is constructed.
- When used for a single table expression
VALUE #( table_expo )
.
The operator
- creates initial values for any non-generic data types
- constructs the content of
- structured types
- table types
- controls the type of the result of table expressions and so enables a default value to be specified for unfound rows
The content of the result is determined by the parameters specified in parentheses. The syntax used in pass by parameter depends on the type used when the value was constructed. There are specialized categories of pass by parameter for each possible type.
- Pass by parameter when constructing values:
- If a single table expression is specified as a parameter, then
VALUE
does not construct a value. Instead it controls the type of the result.
In an assignment of a constructor expression to a
data object using VALUE
, the data object is used directly. It is overwritten in full with an initial value or start value before being assigned the values specified in the parentheses.
Notes
- Elementary data types and reference types cannot be specified explicitly with
VALUE
for constructing values, except when an initial value is created. Unlike when using the instance operatorNEW
, the correct result can be achieved by using direct assignments. For this reason, it is not necessary to specify unnamed arguments as single values when usingNEW
(and also not allowed). The use ofVALUE
to control table expressions is not affected by this, since any valid data type can be specified here.
- Arithmetic calculations with the results of
VALUE
for constructing values are not possible (except when creating an initial value). This means that constructor expressions of this type cannot be specified directly in the operand positions of arithmetic expressions. Constructor expressions usingVALUE
used to control table expressions are not affected by this, if the table expressions can be used for calculations using valid results.
- The conversion operator
CO
closes the gap where no elementary data objects can be constructed in operand positions usingVALUE
.
- If a constructor expression with
VALUE
is not used as the source of an assignment to a data object, the value operatorVALUE
creates a new temporary data object whose data type is determined by the specified type and whose content is determined by the parameters passed. This data object is used as the operand of a statement and then deleted. It is deleted when the current statements is closed or after the analysis of a relational expression once the logical value has been determined.
- In assignments to a data object, the target variable is used directly and no temporary data object
is created. This variable is initialized or overwritten in full before the assignment of the values
specified in the parentheses. Its original value, however, is still available in an optional
LET
expression. This is the difference betweenVALUE
and the instance operatorNEW
.
Example
Constructs the values of a structure of type TB declared inland.
DATA(WA) = VALUE td( spryly = 'ER'
AR = 'DEMO'
ms = '111'
text = '...' ).