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

ABAP Objects: Calling private Methods

majcon
SAP Champion
SAP Champion
0 Likes
5,023

Hi,

i would choose an private Method of an global class (for example class: CL_GUI_ALV_GRID private Method: SEARCH_START) in a local class.


class lcl_test definition for testing.
  private section.
    methods test for testing.
  data ref_alv type ref to cl_gui_alv_grid.
endclass.

class lcl_test implementation.
  method for test.
    create object ref_alv ...

* How to call a private Method?
 call method ref_alv->search_start( ). "not possible!    
  endmethod.
endclass.

Is this possible?

Regards,

Damir

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,579

it is not possible ....can u describe the exact func that u required so that i can find some public method which would help u...

9 REPLIES 9
Read only

Former Member
0 Likes
2,579

NO!

Private Method can call only into its own class.

Max

Read only

Former Member
0 Likes
2,579

Hi,

You can't call a private method since it is "private". Private method can be called within the class where it is defined. We can use public methods or protected methods through inheritance.

regards

austin

Read only

FredericGirod
Active Contributor
0 Likes
2,579

Hi,

private is private, so it's not possible to play with it.

Rgd

Frédéric

Read only

hymavathi_oruganti
Active Contributor
0 Likes
2,579

u cant call private methods.

Read only

Former Member
0 Likes
2,579

It is used for internal puprose od cl_gui_alv_grid, call method cannot be done externally.

Regards

vijay

Read only

Former Member
0 Likes
2,580

it is not possible ....can u describe the exact func that u required so that i can find some public method which would help u...

Read only

0 Likes
2,579

The context is, that I would write ABAPUnit Tests for an own global class! In this class I have some private Methods, and I would test this methods. So I´m search for a possibility to Test this Methods with ABAPUnit.


class myclass definition.
  private section.
    methods my_method.
endclass.

class myclass implementation.
  method my_method.
  endmethod.
endclass.

class mytest defintion for testing.
  private section.
    methods test for testing.
endclass.

class mytest implementation.
  method test.
*   How to call private Methods from local class myclass?
  endmethod.
endclass.

I couldn´t believe, that it is impossible to test private Methods..

regards,

Damir

Read only

0 Likes
2,579

Damir, of course you can call a private method of a class, if this class has made you a friend with the syntax element FRIENDS (available since Release 6.10). Here is a syntactically correct example, when my_method is a private class method:

REPORT test.

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.

Kind regards,

Michael Kraemer

Read only

0 Likes
2,579

Hi Michael,

thanks!

This solved my problem!

Best regards,

Damir