2022 Sep 19 2:12 PM
Hi.
I need some suggestions. Somebody asked this question.
Imagine there is a stand class and it is having private method. My question is how to access this private method in my program.
Suppose if it is public class method we can call like below.
CREATE OBJECT class_name
Now using that object you can call the method
CALL METHOD class_name->method_name
But as per the theory Private methods can not call outside the class.(my class is standard class is not z class)
I read some where they are saying first call public class method there need to call private method.
How could i call the private method.
CALL METHOD class_name->method_name
Anybody can tell me how to call. if possible sample code Please.
2022 Sep 19 2:30 PM
2022 Sep 19 2:35 PM
You need to learn what means "private".
Only methods of the same class (or friend classes) can access private members.
It's why you need to find an existing public method (or create one) which calls the private method.
2022 Sep 19 2:52 PM
sandra.rossi I think it is an exercice question, not a real question
2022 Sep 19 3:08 PM
2022 Sep 20 2:55 PM
Hi newb,
Hope you are doing well 🙂
Here is the Sample Code which might help you
_________________________
* Class Definition - Includes (Attributes, Methods & Events)<br><br>* Constructor - can directly be printed by using (Object)<br><br>* Sample Method - can only be printed by assigning (Call Method)<br><br><br>CLASS ZSCL_CONSTRUCTOR DEFINITION.<br><br> PUBLIC SECTION.<br> DATA: LV_NAME TYPE string.<br> METHODS: constructor, sample_one. " sample_one - Normal Method<br><br>ENDCLASS.<br><br>CLASS ZSCL_CONSTRUCTOR IMPLEMENTATION.<br><br> METHOD: constructor.<br> LV_NAME = 'Constructor Concept'.<br> WRITE:/ LV_NAME.<br> ENDMETHOD.<br><br> METHOD: sample_one.<br> LV_NAME = 'sample method printing'.<br> WRITE:/ LV_NAME.<br> ENDMETHOD.<br><br>ENDCLASS.<br><br>START-OF-SELECTION.<br><br>DATA: LO_CONSTRUCTOR TYPE REF TO ZSCL_CONSTRUCTOR.<br><br>CREATE OBJECT LO_CONSTRUCTOR. " Constructor - can directly be printed by using (Object)<br><br>CALL METHOD LO_CONSTRUCTOR->sample_one. " Sample Method - can only be printed by assigning (Call Method)<strong><br></strong>
_________________________
I hope you will find the Solution,
Thanks,
Suggu Sandeep.
2022 Sep 20 2:57 PM
sandeepsuggu he asked for private, not for public.
second point, change this CREATE OBJECT, it is old school
2022 Sep 20 3:20 PM
"Reward" is non-sense in this forum of volunteers, prefer "please accept this answer if you find it to be the best answer".
If the rules how to participate in the forum are unclear to the OP, the OP might read "Ask and Answer Questions" at https://developers.sap.com/tutorials/community-qa.html, especially in step 5 "Regularly check your question [...] Select the best answer to your question".