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

Calling a protected method

Former Member
0 Likes
5,864

Hello All,

I want to call a protected method of a call, i was trying to search for a solution and i found two options for this. One is calling the method within the class and other is calling the method by creating a subclass and then declaring the method in the public section of the subclass. Since i am new to this, can anyone send me sample syntax for the above requirement.

Thanks in Advance, Thirumal

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
3,465

Hi Thirumal,

You can make a subclass of the base class and access the method.You can refer to this document for the syntax of how to use inheritance by going through this document..

[Removed by the moderator.]

Or you can go to transaction ABAPDOCU and search in the ABAP Objects section and look for inheritance.

You can also go through this link to see programs using inheritance.

[Removed by the moderator.]

Regards,

SP.

6 REPLIES 6
Read only

Former Member
0 Likes
3,465

Hello Thirumal,

2 options you have already mentioned in your mail. All the time i have used the method within the class. This is very simple. See some coding on the web using keyword "Java protected method". You will find many example.

Thanks,

Amit

Read only

0 Likes
3,465

The PROTECTED method cannot be access inside a program. That is why it has been defined as PROTECTED.

If you want to use that, you will define a SUB Class for that and use it inside that.

You can't use a protected method except from within the class itself, or within one of the subclasses. This means you can't use the method from within in a function module.

Read only

0 Likes
3,465

Hello Amit,

I am seeing lot of hits for the same, but i am not able to find any sample coding for the same.

Thanks,

Thirumal

Read only

0 Likes
3,465

Hello Sylendra,

I dont have access to anyother site other than SDN.

post some sample code if possible.

Thanks in advance,

Thirumal

Read only

3,465

Hi Thirumal,

If you can go through this SDN link, please do it.

I will also post one of the codes regarding Inheritance.

REPORT demo_inheritance.

CLASS counter DEFINITION.

PUBLIC SECTION.

METHODS: set IMPORTING value(set_value) TYPE i,

increment,

get EXPORTING value(get_value) TYPE i.

PROTECTED SECTION.

DATA count TYPE i.

ENDCLASS.

CLASS counter IMPLEMENTATION.

METHOD set.

count = set_value.

ENDMETHOD.

METHOD increment.

ADD 1 TO count.

ENDMETHOD.

METHOD get.

get_value = count.

ENDMETHOD.

ENDCLASS.

CLASS counter_ten DEFINITION INHERITING FROM counter.

PUBLIC SECTION.

METHODS increment REDEFINITION.

DATA count_ten(1) TYPE c.

ENDCLASS.

CLASS counter_ten IMPLEMENTATION.

METHOD increment.

DATA modulo TYPE i.

CALL METHOD super->increment.

WRITE / count.

modulo = count MOD 10.

IF modulo = 0.

count_ten = count_ten + 1.

WRITE count_ten.

ENDIF.

ENDMETHOD.

ENDCLASS.

DATA: count TYPE REF TO counter,

number TYPE i VALUE 5.

START-OF-SELECTION.

CREATE OBJECT count TYPE counter_ten.

CALL METHOD count->set EXPORTING set_value = number.

DO 20 TIMES.

CALL METHOD count->increment.

ENDDO.

<b>Close the thread once the problem is resolved.</b>

Regards,

SP.

Read only

Former Member
0 Likes
3,466

Hi Thirumal,

You can make a subclass of the base class and access the method.You can refer to this document for the syntax of how to use inheritance by going through this document..

[Removed by the moderator.]

Or you can go to transaction ABAPDOCU and search in the ABAP Objects section and look for inheritance.

You can also go through this link to see programs using inheritance.

[Removed by the moderator.]

Regards,

SP.