can someone tell me what is type casting here.
what is the difference between
lr_entity = lr_result->get_first( ).
lr_entity ?=lr_result->get_next( ).
lr_entity type ref to cl_crm_bol_entity, lr_result type ref to if_bol_entity_col. lr_entity = lr_result->get_first( ). while lr_entity is bound. ------------ ------------- lr_entity ?= lr_result->get_next endwhille.
what is the difference between = and ?=
Edited by: Muralidhar Chatna on Apr 10, 2010 9:05 AM
Edited by: Muralidhar Chatna on Apr 10, 2010 9:12 AM
Arun Prakash Karuppanan replied
The ?= is a type casting operator that upcasts/downcasts one object type to another.
a ?= b.
For this to be successful, a & b should be compatible.
If a and b are of type some class, then.
a should be a derived class of b(downcasting) OR super class of b(upcasting)
If one of them/both is an interface, the run time object(class) type should satisfy the above condition.
Both objects implementing the same interface does not guarantee type casting compatibility. For example, cl_crm_bol_entity and cl_bsp_wd_value_node are not compatible even though they have implemented a common interface if_bol_bo_property_access.
In the example that you provided, there is no need for using the ?= operator. because, the return type in both cases is cl_crm_bol_entity.
Suppose lr_result is of type if_bol_bo_col. The return type for both get_first and get_next methods is if_bol_bo_property_access. If you are assigning the returned object to an object reference of type cl_crm_bol_entity, then you will have to use the cast operator. The typecasting here is possible because, cl_crm_bol_entity implements the interface if_bol_bo_property_access.