Skip to Content
avatar image
Former Member

type casting

Hi all,

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 ?=

regards,

Muralidhar Prasad.C

Edited by: Muralidhar Chatna on Apr 10, 2010 9:05 AM

Edited by: Muralidhar Chatna on Apr 10, 2010 9:12 AM

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • Best Answer
    Apr 10, 2010 at 09:24 AM

    Hi,

    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.

    Regards,

    Arun Prakash

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Apr 10, 2010 at 07:27 AM

    By making use of ?= operator you are typecasting the reference type here. Since lr_result->get_next will return you an entity which may or may not be in the same reference. In order to be on the same reference type we make use of ?= operator

    Regards,

    Harshit

    Add comment
    10|10000 characters needed characters exceeded