SAP CONSTRUCTOR EXPRESSIONS

Get Example source ABAP code based on a different SAP table
  


ARTICLE

Constructor Operators for Constructor Expressions
• # ABAP_ELEMENT

Syntax
... NEW| VALUE| CONV| CAST| REF| EXACT| COND| SWITCH type( ... ) ...

Effect
A constructor expression consists of a
predefined constructor operator,
a data type or object type type that matches the operator and that can be derived implicitly from the operand position,
and type-specified parameters specified in parentheses.
Each constructor expression generates a result whose data type is determined using the specified type. The parameters specified in p arentheses are used to pass input values. The following constructor operators exist:
The instance operator NEW is used to generate objects in operand positions. The result is a reference variable of the static type type that points to the new object. The input values determine the content of the new object.
The value operator VALUE is 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 CONV is used for conversions between data types in operand positions. The result is a data object of the specified type type produced by the conversion from an input value.
The casting operator CAST is used for down casts of reference variables in operand positions. The result is a reference variable of the static type type produced by the assignment from an input value.
The reference operator REF is 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 lossless operator EXACT is 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 conditional operators COND and SWITCH are 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 generate an initial value cannot be specified directly in an arithmetic expression. This is because it never matches the operand type here. Expressions with the operators NEW and CAST can be positioned directly before the object component selector -> and can occur in chainings.
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.
ABAP Code Snippet If 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.

Note
The constructor operators can be classified as follows:
NEW and VALUE construct new values whose parts can be passed (except when the initial value is generated), while CONV, CAST, REF, and EXACT convert a single passed value.
NEW, CAST, and REF always return reference variables, whereas VALUE, CONV, and EXACT return all types of data objects.