Вы находитесь на странице: 1из 2

Object Oriented ABAP Commands and Operators

=> usually indicates a reference to a static method or attribute and therefore is not dependent upon a particular instance

Typical use of static method is when writing to a log file cl_lso_wdui_logfile=>instance->write_leaving_info( ). Static attributes are usually final and therefore equivalent to CONTANTS lv_display_tracking = cl_wd_uielement=>e_visible-visible.

=> can also reference a type

-> indicates a reference to an instance method or attribute and therefore is dependent upon a particular instance

Method example lo_interfacecontroller->get_participants_for_foup( ) Attribute example wd_this->gr_fpm

= indicates upcasting, widening the cast from a subclass to its super class. The super class variable will only see the values of the subclass that are defined in the super class. The example below is from Java code not ABAP code but you get the idea. At the completion of this code, superV will only have access to the dog's attributes that are associated with all animals.

SuperAnimal superV;

SubDog subV = new SubDog( ); superV = subV;

?= indicates downcasting, narrowing the cast. It is asking the question "Is what appears in the super class variable an instance of the subclass?" In the example below, there is a catalog object that is defined a subclass of a generic business object. A course instance is defined as just a generic business object. The code below attempts to populate the subclass variable with the superclass instance and will succeed if the instance is of the subclass catalog object.

lr_catalog_object TYPE REF TO if_lso_bo_catalog_object. lv_course_instance TYPE REF TO if_lso_bo_generic.

lr_catalog_object ?= lv_course_instance.

IS BOUND / IS NOT BOUND checks whether a reference variable contains a valid reference. It is equivalent to IS NOT INITIAL / IS INITIAL for object references (i.e., defined with addition REF TO). You could use IS NOT INITIAL instead of IS BOUND but in the first case you'd only be ensuring the value was not null whereas in the latter case you are ensuring it is a valid reference to the object of interest and can therefore be dereferenced. Also, it makes it much clearer that you are dealing with an object reference as opposed to a simple variable, structure or table. The code below is testing whether the above downcasting was successful. In other words, did the super class contain an instance of the subclass?

IF lr_catalog_object IS BOUND.

Вам также может понравиться