Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to access private method in my Program.

former_member196331
Active Contributor
0 Kudos
1,423

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.

7 REPLIES 7

FredericGirod
Active Contributor
0 Kudos
1,346

You have to search about LOCAL FRIEND

Sandra_Rossi
Active Contributor
1,346

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.

FredericGirod
Active Contributor
0 Kudos
1,346

sandra.rossi I think it is an exercice question, not a real question

Sandra_Rossi
Active Contributor
0 Kudos
1,346

frdric.girod Does that make a difference? 😄

SugguSandeep
Contributor
0 Kudos
1,346

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.

0 Kudos
1,346

sandeepsuggu he asked for private, not for public.

second point, change this CREATE OBJECT, it is old school

1,346

"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".