‎2010 Nov 16 11:21 AM
Hi,
I tried to inherit a subclass from super class. In se38, i created supercalss and subclasses as local classes. Here in subclass, the system was expecting the keyword REDEFINITION while resuing the same method in the subclass.
But when i do the same thing in SE24 for creating a Global Class, the system was not asking to redefine the method.
Can anyone tell me what could the difference?
Regards,
Prabu
‎2010 Nov 16 12:04 PM
You need to redefine method only if it has different body (implementation) in the subclass. All the others which have been defined in public section of superclass will stay as they are. So within subclass you can access them too.
In global class the principle is the same. If you go to cl_gui_alv_grid you shall see lots of blue-marked methods which originally comes from some superclass. Double click such method and system will prompt the message saying who is the real owner (who implements the method). The redefinition of certain methods takes place only for choosen ones (as within local classes). To prove that from menu select Goto -> Public section and search for FREE method. You shall see that next to its definition there is keyword REDEFINITION . So only this methods which has this addtion will receive their new implementation in the sublcass. They also are no longer blue-marked but become black.
Regards
Marcin
‎2010 Nov 16 12:22 PM
Hi Marcin,
Thanks for your response.
I still have the same doubt.
See the following code, i ahve used the only method DISPLAY in both superclass and subclass. Here if i remove the keyword REDEFINITION from the subclass. I am getting the error as " method DISPLAY as already been declared "
class lc_superclass DEFINITION.
PUBLIC SECTION.
METHODS : display.
ENDCLASS.
CLASS lc_superclass IMPLEMENTATION.
METHOD display.
ENDMETHOD.
ENDCLASS.
CLASS lc_subclass DEFINITION INHERITING FROM lc_superclass.
PUBLIC SECTION.
METHODS : display REDEFINITION.
ENDCLASS.
CLASS lc_subclass IMPLEMENTATION.
METHOD display.
ENDMETHOD.
ENDCLASS.
Can you please correct if i am wrong.
Regards,
Prabu
‎2010 Nov 16 12:33 PM
By default method display is available in lc_subclass (as it is defined in public section of superclass). In principle the public section is shared accross class hierarchy (subclass sees superclass's components, but not vice versa). So in your case you can call method display using subclass object reference. So no need to have METHODS display definition nor implementation in the subclass.
On the other hand if you are not satisfied with its implementation all you can do about that is redefining it in the subclass. The keyword REDEFINITION in this case is a must. When you remove it, the system will try to define display method anew, but as it already sees its definition (coming from superclass's public section) it doesn't allow you to do so.
In simple words. You must leave redefinition keyword if you use METHODS display within subclass. If implementation is ok then remove sublcass definition at all.
Hope it is clear.
Regards
Marcin
‎2010 Nov 16 3:01 PM
Once you inherit your Subclass from the Super Class, you would see all the Public and Protected methods in your Super Class. Now to redefine any particular method, place cursor on the method and press the "Redefine" button. This button is available as 3rd last in the same toolbar where you see the buttons for Parameters, exceptions and so on.
To undo the redefinition of any redefined method, you use the button "Undo Redefinition" available next to Redefinition button.
Check this help: [Extending Subclasses|http://help.sap.com/saphelp_NW70EHP1core/helpdata/en/2f/8bbf7bbb4111d2958600a0c94260a5/frameset.htm]
Regards,
Naimesh Patel