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: 
Read only

How do we call Private Methods?

Former Member
0 Likes
4,346

Hello Friends,

How do we call Private Methods? How it would be in case of Subclass?

Thanks & Regards

Sathish Kumar

1 ACCEPTED SOLUTION
Read only

Former Member
1,666

Hi Satish,

You can call a private method of a class, if this class has made you a friend with the syntax of FRIEND

REPORT zex33.

CLASS mytest DEFINITION FOR TESTING.

PRIVATE SECTION.

METHODS test FOR TESTING.

ENDCLASS.

CLASS myclass DEFINITION FRIENDS mytest.

PUBLIC SECTION.

CLASS-METHODS my_method.

ENDCLASS.

CLASS myclass IMPLEMENTATION.

METHOD my_method.

ENDMETHOD.

ENDCLASS.

CLASS mytest IMPLEMENTATION.

METHOD test.

CALL METHOD myclass=>my_method.

ENDMETHOD.

ENDCLASS.

If my_method is not a class method, then you need to create an object of the class first, whose methods you want to test.

6 REPLIES 6
Read only

Former Member
0 Likes
1,666
Read only

Former Member
0 Likes
1,666

you can try this one.

CALL METHOD method .

CALL METHOD super->method.

still you have any doubt send your doubt clearly.

regards

veera nagi reddy

Read only

Former Member
0 Likes
1,666

Hi Sathish Kumar,

Go through the following Code

DATA: L_APP TYPE STRING VALUE 'EXCEL' ,

L_PARAMETER TYPE STRING VALUE 'C:\ZRPP030.XLS'.

<b> CALL METHOD CL_GUI_FRONTEND_SERVICES=>EXECUTE</b> EXPORTING

APPLICATION = L_APP

PARAMETER = L_PARAMETER

EXCEPTIONS

CNTL_ERROR = 1

ERROR_NO_GUI = 2

BAD_PARAMETER = 3

FILE_NOT_FOUND = 4

PATH_NOT_FOUND = 5

FILE_EXTENSION_UNKNOWN = 6

ERROR_EXECUTE_FAILED = 7

SYNCHRONOUS_FAILED = 8

NOT_SUPPORTED_BY_GUI = 9

others = 10.

Regards

Sreeni

Read only

Former Member
0 Likes
1,666

hi

<b>

Private methods</b>

Can only be called from inside the class. They are placed in the PRIVATE section of the class.

<i><b>Private section. Not accessable by subclasses</b></i>

<b>

Private attributes</b>

Private attributes are defined in the PRIVATE section. The can only be viewes and changed from within the class. There is no direct access from outside the class.

PRIVATE SECTION.

DATA: name(25) TYPE c,

planetype LIKE saplane-planetyp,

with regards

vinayaka

Read only

Former Member
1,667

Hi Satish,

You can call a private method of a class, if this class has made you a friend with the syntax of FRIEND

REPORT zex33.

CLASS mytest DEFINITION FOR TESTING.

PRIVATE SECTION.

METHODS test FOR TESTING.

ENDCLASS.

CLASS myclass DEFINITION FRIENDS mytest.

PUBLIC SECTION.

CLASS-METHODS my_method.

ENDCLASS.

CLASS myclass IMPLEMENTATION.

METHOD my_method.

ENDMETHOD.

ENDCLASS.

CLASS mytest IMPLEMENTATION.

METHOD test.

CALL METHOD myclass=>my_method.

ENDMETHOD.

ENDCLASS.

If my_method is not a class method, then you need to create an object of the class first, whose methods you want to test.

Read only

Former Member
0 Likes
1,666

Hi Sathish.

The syntax for calling a private method is no different from that of calling any other instance method.

It is call method object->method

exporting

<>

importing

<>.

But remember, that you can call the private method only within the same class.

Hope this helps. Remember to reward points if it does.

Rgds,

Prashanth.

SAP.