‎2006 Dec 07 1:36 PM
Hi All,
In ABAP objects, is it possible to use same method name with different signature
in the same class. In Se24, i have build a class xyz and a method A. The method A has a string as importing parameter. I have to use the same method A with an internal table as importing parameter. Any code samples and replies would be really appreciated.
Thanks,
Ricky
‎2006 Dec 07 1:45 PM
Hi,
I think you are asking about overriding. There is no concept in OO ABAP. You can achieve paritially using Multiple inheritance technique in ABAP.
Here using SUPER keyword we can deferenciate Parent class and Child class. Based on SUPER keyword you can achieve overridding concept.
Regards
Bhupal Reddy
‎2006 Dec 08 7:02 AM
In abap objects overloding(we can change the signature ) is possible only with construcor.
It is not possible with methods and the signatures can not be changed.
&----
*& Report ZTEST_TWO *
*& *
&----
*& *
*& *
&----
REPORT ZTEST_TWO .
class c_base definition.
public section.
methods: constructor importing value(p_name) type string,
m_show1,
m_show2.
private section.
data a_name type string.
endclass.
----
class c_derived definition inheriting from c_base.
public section.
methods: constructor importing value(p_name1) type string
value(p_name2) type string,
m_show1 redefinition.
private section.
data a_name type string.
endclass.
----
class c_base implementation.
method constructor.
a_name = p_name.
endmethod.
method m_show1.
write: / 'Show1 :', a_name.
endmethod.
method m_show2.
write: / 'Show2 :', a_name.
endmethod.
endclass.
----
class c_derived implementation.
method constructor.
call method: super->constructor exporting p_name = p_name1.
a_name = p_name2.
endmethod.
method m_show1.
write: / 'Show1_r:', a_name.
endmethod.
endclass.
----
data o type ref to c_derived.
----
start-of-selection.
----
create object o exporting p_name1 = 'Base...' p_name2 = 'Derived...'.
call method: o->m_show1,
o->m_show2.
‎2006 Dec 08 7:30 AM
Hi,
In ABAP objects we dont have overloading. But we can acheive it using OPTIONAL parameters. To the method A itself add one more OPTIONAL parameter of type your internal table then you can use the same method. Als make sure your String parameter is also optional so that you can pass which ever you need to pass.
Example.
CLASS xyz definition.
Methods: A importing A type String OPTIONAL itab type <ttype> OPTIONAL.
ENDCLASS.
Regards,
Sesh
‎2006 Dec 08 7:33 AM
Hi,
In ABAP objects we dont have overloading. But we can acheive it using OPTIONAL parameters. To the method A itself add one more OPTIONAL parameter of type your internal table then you can use the same method. Als make sure your String parameter is also optional so that you can pass which ever you need to pass.
Example.
CLASS xyz definition.
Methods: A importing A type String OPTIONAL itab type <ttype> OPTIONAL.
ENDCLASS.
Regards,
Sesh
‎2006 Dec 11 5:04 AM
hi,
Sorry we cannot do that in ABAP because ABAP doesnt support <b>overloading</b> concept. overloading is possible only with constructor .