SAP CONVERSION REFERENCES OBJECTS



Get Example source ABAP code based on a different SAP table
  



Assignments Between Object Reference Variables
Object reference variables are either class references or interface reference variables.
ITOC

Upcast in Object References
An upcast in object references is possible in the following cases:
If both static types are classes, the class of the target variable must be the same class or a superclass of the source variable.
If both static types are interfaces, the interface of the target variable must be the same interface or a component interface of the source variable.
If the static type of the target variable is an interface and the static type of the source variable is a class, the class of the source variable must implement the interface of the target variable.
If the static type of the target variable is a class and the static type of the source variable is an interface, the class of the target variable must be the generic type or the root class object.

ABAP_EXAMPLE_VX5
The statement iref = NEW class( ) is an upcast, because it is followed by an interface reference variable that points to an object of a class.
ABEXA 00918
ABAP_EXAMPLE_END

Downcast in Object References
For all cases not specified under the upcast, assignments can only be programmed using a downcast.

ABAP_EXAMPLE_VX5
Declaration of interfaces and classes, creation of an object in the subclass, and access to the components of the object. In the statement CREATE OBJECT, an upcast occurs implicitly from c2 to iref. The interface reference iref can only be used to access the components declared in the interface i2. Method m1 of the object cannot be called using iref. Once the object reference has been assigned to the class reference cref using a downcast, m1 can be accessed dynamically but not statically.
ABEXA 01703
ABAP_EXAMPLE_END