A class can grant friendship to another class. By granting friendship , it allows another class to:-
Use its private components.
Instantiate it, irrespective of the CREATE PRIVATE addition.
-------------------------------------------------------------------------------------------
REPORT YSUBDEL.
CLASS C1 DEFINITION DEFERRED.
CLASS C2 DEFINITION CREATE PRIVATE FRIENDS C1 .
PROTECTED SECTION.
DATA : NUM TYPE I VALUE 5.
METHODS : M2.
ENDCLASS.
CLASS C2 IMPLEMENTATION.
METHOD M2.
WRITE:/5 'I am method m2 in C2'.
ENDMETHOD.
ENDCLASS .
class c1 definition.
public section .
methods : m1.
endclass.
class c1 implementation.
method m1.
DATA : OREF2 TYPE REF TO C2.
CREATE OBJECT OREF2.
WRITE:/5 OREF2->NUM.
CALL METHOD OREF2->M2.
ENDMETHOD.
endclass.
START-OF-SELECTION.
DATA : OREF1 TYPE REF TO C1.
CREATE OBJECT OREF1.
CALL METHOD OREF1->M1.
Output:
5
I am method m2 in 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 abap friend class. Show all posts
Showing posts with label abap friend class. Show all posts
Subscribe to:
Posts (Atom)