‎2008 Jun 27 7:52 PM
Hi All,
i have a class CL_CRM_DOCUMENTS_PLM and private method GET_DOCUMENT_DATA.
Now how could i call this private method in my ABAP Editor ?
Regards.
‎2008 Jun 27 8:00 PM
Hi,
First you need to create a an object of the class like
CREATE OBJECT class_name
Now using that object you can call the method
CALL METHOD class_name->method_name
Regards,
Chandru
‎2008 Jun 27 8:00 PM
Hi,
First you need to create a an object of the class like
CREATE OBJECT class_name
Now using that object you can call the method
CALL METHOD class_name->method_name
Regards,
Chandru
‎2008 Jun 27 8:02 PM
Hi Chandru,
i get an error that you cannot create the object outside the class .
Since the method GET_DOCUMENT_DATA is private i cannot call it outside the class.
Regards.
‎2008 Jun 27 8:04 PM
Private methods can not be called from outside the class,thats why they are private.
‎2008 Jun 27 8:06 PM
‎2008 Jun 27 8:08 PM
Private methods can only be called from another method in the same class. As this class is delivered by SAP you can do nothing with this class.
‎2008 Jun 27 8:07 PM
‎2008 Jun 27 8:10 PM
Inherting works only for protected methods,not for private methods. private methods cannot be called in an inherited class.
The only thing is too copy the source code into an own class or do amdification on the SAP class.
‎2008 Jun 27 8:18 PM
Check if this private method is being used by some public method. If yes u can call the public method from ur abap code.
‎2008 Jun 27 8:34 PM
Hi Rawoof,
Welcome do SDN Forum.
Please dont't forget to read the Forum Rules Document on [rules of engagement|https://wiki.sdn.sap.com/wiki/x/FgQ] to know the rules we must follow to post here.
Really you can't call any private Component outside its class.
Don't forget to close this thread once your question be answered !
Greetings.
Marcelo Ramos
Edited by: Marcelo Ramos on Jun 27, 2008 5:24 PM
‎2008 Jun 28 5:39 AM
hi
for Accessing a private Method of a class you have to Call it from a Public Method of the same class.
Private Methods are not accessible outside the class or even in the derived class. If you want to access the Private Method inside Derived Class you have to Change Its ATTRIBUTE to Protected which behaves like Private Outside Class but As Public Inside the derived Class.
Hope this will help.
Reward if useful
Sumit Agarwal
‎2008 Jun 28 5:40 AM
HI
dear it is not possible to call a private method directly,Instead what you can do is you calla public method of that class inside that public method you can call the private members of the class.
regards
PAVAN
‎2008 Jun 28 6:01 AM
hi,
plz check the steps,
1. Declare a method in public section of the class
CL_CRM_DOCUMENTS_PLM.
2. In the implementation of the public method , call the private method GET_DOCUMENT_DATA..
3. Call the public method from your report program.
Reward if found helpful.
Anirban Bhattacharjee
‎2008 Jun 28 6:50 AM
Hii!
You cannot call the private method directly.
To call a private method,
You call a public method first,
and then from that method
call that private method.
Regards
Abhijeet Kulshreshtha
‎2008 Jun 28 11:40 AM
hi check this example..
 Class C2 is created using CREATE PRIVATE option. That means, only the class itself and its friends can instantiate this class.
 Class C2 has a private method M2 and a private attribute , NUM. This means that these components can be accessed by class C2 itself and its friends.
 Now, C2 has granted friendship to class C1.
 So, methods of class C1 can access private components of C2 as well as can instantiate class C2.
report
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.
‎2008 Jun 28 1:57 PM
Hi rawoof,
private methods can only be called from within the class. If you get an error like "cannot create the object outside the class" then the constructor is private, too. This is a technique frequently used in factory methods, in that case You should have a method like get_instance that will create the object and give you a refernece. If a method is declared private, it will usually not make sense to call it from outside. Check the wehere-used-refernce of the private method to find out how it is used in public method.
Regards,
Clemens
‎2008 Jun 28 10:47 PM