‎2006 Jul 06 5:26 AM
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
‎2006 Jul 06 6:02 AM
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.
‎2006 Jul 06 5:31 AM
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
‎2006 Jul 06 5:43 AM
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.
‎2006 Jul 06 6:04 AM
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
‎2006 Jul 06 6:09 AM
Hello Sylendra,
I dont have access to anyother site other than SDN.
post some sample code if possible.
Thanks in advance,
Thirumal
‎2006 Jul 06 6:28 AM
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.
‎2006 Jul 06 6:02 AM
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.