Constructor Operators for Constructor Expressions
7.31 | 7.40 | 7.54
A constructor expression consists of a
- predefined constructor operator,
- a data type or object type
typethat matches the operator and that can be derived implicitly from the operand position using
- and type-specified parameters specified in parentheses.
Each constructor expression creates a result whose data type is determined using the specified type. The parameters specified in parentheses are used to pass input values. The following constructor operators exist:
- The instance operator
NEWis used to create objects in operand positions. The result is a reference variable of the static type
typethat points to the new object. The input values determine the content of the new object.
- The value operator
VALUEis used to fill complex data objects with values in operand positions, create initial values of any data type, or control the results of table expressions. The result is a data object of the specified type
type. The input values determine the content of the result.
- The conversion operator
CONVis used for conversions between data types in operand positions. The result is a data object of the specified type
typeproduced by the conversion from an input value.
- The casting operator
CASTis used for down casts of reference variables in operand positions. The result is a reference variable of the static type
typeproduced by the assignment from an input value.
- The reference operator
REFis used to construct a data reference to a data object in operand positions or to control the results of table expressions. The result is a data reference variable.
- The component operator
CORRESPONDINGis used to build a structure or an internal table at an operand position. The result is a structure or internal table, whose components are filled with values from identically named components or from argument components specified using a mapping rule.
- The lossless operator
EXACTis used to create a value in an operand position without losing data. The result is a data object of the specified type, derived from a lossless assignment or a lossless calculation.
- The reduction operator
REDUCEconstructs a value from condition iterations or from table iterations.
- The filter operator
FILTERconstructs an internal table by filtering the rows of an internal table.
- The conditional operators
SWITCHare used to create values or raise class-based exceptions in operand positions in accordance with conditions. The result is determined by logical expressions or by a case distinction.
A constructor expression can be specified in general expression positions and
functional positions with an appropriate
operand type. The result is used here as an operand. In a
calculation expression or
relational expression, the specified type
type is incorporated into the
calculation type or
comparison type. An
expression with the operator
VALUE that is not used to create an initial value cannot be specified directly in an
This is because it never matches the operand type here. Expressions with the operators
CAST can be positioned directly before the
object component selector
-> and can occur in
Visible, usable data types and classes can be specified for
type in the current position. This includes
predefined ABAP type,
types defined using
TYPES, types from ABAP Dictionary, and both local and global classes.
If the data type required in an operand position is unique and fully recognizable, the
# character can be used instead of an explicitly specified type
type and the
operand type is used.
REF is used,
# can be specified for non-unique operand types as well. In the case of
EXACT, the operand type can also be generic.
LET expressions can be used to define local help fields in all suitable constructor expressions.
- Constructor operators can be classified as follows:
- Constructor operators like
VALUEconstruct new values whose parts can be passed (except when the initial value is created), whereas constructor operators like
EXACTconvert a single passed value.
- Constructor operators like
REFalways return reference variables, whereas constructor operators like
EXACTreturn all types of data objects.