REPORT YSUBOOPS18.
class c1 definition.
public section.
methods : m1.
endclass.
class c1 implementation.
method m1 .
write:/5 ' I am m1 of c1'.
endmethod.
endclass.
class c2 definition inheriting from c1.
public section.
methods : m1 redefinition.
endclass.
class c2 implementation.
method m1.
write:/5 'I am m1 of c2'.
endmethod.
endclass.
START-OF-SELECTION.
DATA : OREF1 TYPE REF TO C1,
OREF11 TYPE REF TO C1,
OREF111 TYPE REF TO C1,
OREF2 TYPE REF TO C2 .
CREATE OBJECT : OREF1 ,
OREF11 TYPE C2,
OREF111 ,
OREF2 .
OREF111 = OREF2.
CALL METHOD : OREF1->M1 , “ Output : I am m1 of c1
OREF11->M1 , “ Output : I am m1 of c2
OREF111->M1, “ Output : I am m1 of c2
OREF2->M1 . “ Output : I am m1 of c2
Output
I am m1 of c1
I am m1 of c2
I am m1 of c2
I am m1 of c2
Here you can find examples and sample programs related to ABAP Report Programs, ALV Grid/List Programs, BDC, HR ABAP, Function Modules, BAPIs, BADIs, Smartforms, SapScripts, etc.
Google Search - Blog...........
Showing posts with label sap abap class implementation. Show all posts
Showing posts with label sap abap class implementation. Show all posts
ABAP - OOPS: Static Attributes Exist Only Once Per Inheritance Tree In Method Programming
Static attributes only exist once in each inheritance tree. One can change them from outside the class using the class component selector with any class name, or within any class in which they are shared. They are visible in all classes in the inheritance tree.
-------------------------------------------------------------------------------------------
REPORT YSUBDEL.
CLASS C1 DEFINITION .
PUBLIC SECTION.
class-data : num type i.
ENDCLASS.
CLASS C1 IMPLEMENTATION .
ENDCLASS.
CLASS C2 DEFINITION INHERITING FROM C1.
ENDCLASS.
CLASS C2 IMPLEMENTATION.
endclass.
CLASS C3 DEFINITION INHERITING FROM C1.
ENDCLASS.
START-OF-SELECTION.
C3=>NUM = 10.
WRITE:/5 C2=>NUM.
Output 10
-------------------------------------------------------------------------------------------
REPORT YSUBDEL.
CLASS C1 DEFINITION .
PUBLIC SECTION.
class-data : num type i.
ENDCLASS.
CLASS C1 IMPLEMENTATION .
ENDCLASS.
CLASS C2 DEFINITION INHERITING FROM C1.
ENDCLASS.
CLASS C2 IMPLEMENTATION.
endclass.
CLASS C3 DEFINITION INHERITING FROM C1.
ENDCLASS.
START-OF-SELECTION.
C3=>NUM = 10.
WRITE:/5 C2=>NUM.
Output 10
ABAP - Class That Can Be Instantiated Within Implementation Of Another Class.
REPORT YSUBOOPS17 .
class class1 definition.
public section.
methods : method1 .
endclass.
class class2 definition.
public section.
methods : method2 .
endclass.
class class1 implementation.
method :method1.
data : i_num type i value 2.
write:/5 i_num.
endmethod.
endclass.
class class2 implementation.
method : method2.
data : obj1 type ref to class1.
create object obj1.
call method obj1->method1.
endmethod.
endclass.
start-of-selection.
data : my_obj type ref to class2.
create object : my_obj.
call method my_obj->method2.
Output 2
class class1 definition.
public section.
methods : method1 .
endclass.
class class2 definition.
public section.
methods : method2 .
endclass.
class class1 implementation.
method :method1.
data : i_num type i value 2.
write:/5 i_num.
endmethod.
endclass.
class class2 implementation.
method : method2.
data : obj1 type ref to class1.
create object obj1.
call method obj1->method1.
endmethod.
endclass.
start-of-selection.
data : my_obj type ref to class2.
create object : my_obj.
call method my_obj->method2.
Output 2
Subscribe to:
Posts (Atom)