PARAMETER | DATA | OBJECT |
DEFINITION | DATA lr_ref TYPE REF TO data. | DATA lr_object TYPE REF TO object. |
CREATION | CREATE DATA lr_ref TYPE REF TO (‘ZIF_INSTANCE’). | CREATE OBJECT lr_object TYPE (‘ZCL_CLASS’). |
DEREFERENCE | It can be dereferenced. The object or any value can be assigned to dereferenced reference variable. lr_ref->* = lr_object | Object references cannot be dereferenced. This notation ->* cannot be used. |
CONVERSION OR CASTING | How to convert a value or an object in to a reference: it can be converted in the following two ways. lr_ref->* = value or object lr_ref = REF #(value/obj) | How to cast an object. lr_object2 = CAST zcl_object2( lr_object ). |
USAGE | used to create data references | Used to create objects for classes. |
ASSIGNMENT | An object or any value cannot be assigned to a data reference variable. It must be deferenced in order to assign a value. lr_ref->* = lr_object. lr_ref->* = ‘string_value’ | Only objects can be assigned. It can be assigned directly without dereference. DATA lr_object TYPE REF TO object. DATA lr_object2 TYPE REF TO object. CREATE OBJECT lr_object TYPE (‘ZCL_CLASS’). lr_object2 = lr_object. |
POSSIBLE SYNTAX ERROR | As mentioned before, values cannot be assigned directly without dereference. For example: lr_ref = ‘String_value’. This line of code will result in the below Error. “The type of ‘lr_interface1’ cannot be converted to the type of ‘lr_ref’ | If the types of data objects are different, then it must be casted during the assignment. Otherwise you will get the below error. ‘The type of ‘lr_object’ cannot be converted to the type of ‘lr_object2’. |