‎2010 Nov 02 5:03 AM
Hello,
Please can someone help me with friends class method call. in global classes
Thanks
Megh
Moderator message: please search for available information/documentation before asking.
Edited by: Thomas Zloch on Nov 2, 2010 5:29 PM
‎2010 Nov 02 6:00 AM
Moderator Message: I will continue to remove any content you post whilst it's copy pasted from SAP Help. You have been warned.
Edited by: Neil Gardiner on Nov 2, 2010 5:07 PM
‎2010 Nov 02 8:12 AM
What is your exact problem?
The class whose private and protected section you want to use, needs declaration of its friends. You do it in Friends tabstrip. All these classes are allowed then to access these "hiden" sections from outside of the class. Below example how it works with local classes. For global ones the principle stays the same
CLASS lcl_main DEFINITION DEFERRED.
CLASS lcl_other DEFINITION FRIENDS lcl_main. "only LCL_MAIN can use may hiden sections
PROTECTED SECTION.
METHODS prot_meth.
PRIVATE SECTION.
METHODS priv_meth.
ENDCLASS.
CLASS lcl_other IMPLEMENTATION.
METHOD prot_meth.
WRITE / 'This is protected method of class lcl_other'.
ENDMETHOD. "prot_meth
METHOD priv_meth.
WRITE / 'This is private method of class lcl_other'.
ENDMETHOD. "priv_meth
ENDCLASS.
CLASS lcl_main DEFINITION.
PUBLIC SECTION.
METHODS call_friends_methods.
PRIVATE SECTION.
DATA mr_my_friend TYPE REF TO lcl_other.
ENDCLASS.
CLASS lcl_main IMPLEMENTATION.
METHOD call_friends_methods.
CREATE OBJECT mr_my_friend.
mr_my_friend->prot_meth( ).
mr_my_friend->priv_meth( ).
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
DATA gr_main TYPE REF TO lcl_main.
CREATE OBJECT gr_main.
gr_main->call_friends_methods( ).
Regards
Marcin
‎2010 Nov 02 10:01 AM