Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

ABAP methods overloading

Former Member
0 Likes
2,179

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

5 REPLIES 5
Read only

Former Member
0 Likes
1,250

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

Read only

former_member842213
Participant
0 Likes
1,250

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.

Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
1,250

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

Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
1,250

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

Read only

Former Member
0 Likes
1,250

hi,

Sorry we cannot do that in ABAP because ABAP doesnt support <b>overloading</b> concept. overloading is possible only with constructor .