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

OOPs+protected class

Former Member
0 Likes
762

HI,

I want to use methods from protected class directly by creating instace of that class.

without inheriting it to child class.

Is it posible.......... direclty its not possible. Is there any other way?

Regards,

sarath

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
692

Hi,

if class A contains protected methods and you want to use it from class B, when B is not a child of A, then you can define class B as friend class in class A. With that you can use protected and private methods.

See [Defining Friends Relationships|http://help.sap.com/saphelp_nw70/helpdata/EN/b5/693ec8185011d5969b00a0c94260a5/frameset.htm]

Regards Rudi

6 REPLIES 6
Read only

Former Member
0 Likes
693

Hi,

if class A contains protected methods and you want to use it from class B, when B is not a child of A, then you can define class B as friend class in class A. With that you can use protected and private methods.

See [Defining Friends Relationships|http://help.sap.com/saphelp_nw70/helpdata/EN/b5/693ec8185011d5969b00a0c94260a5/frameset.htm]

Regards Rudi

Read only

0 Likes
692

Hi,

Thanks for u r replay.

I want to use that protected class in ABAP editor.

Not in a class.

Regards,

sarath

Read only

0 Likes
692

Hi,

I think, then is the way to achieve this to define a local class that inherits from the global class. Then you can define a public method within this local class that calls the protected method.

Regards Rudi

Read only

Former Member
0 Likes
692

Hi,

Only Child Classes and Friend Classes can use the Protected/Private methods or Protected/Private variables.

Read only

Former Member
0 Likes
692

Hi,

We can use the protected metothod by inheriting only.

the sample code is

CLASS c2 DEFINITION INHERITING FROM CL_GUI_ALV_GRID.

PUBLIC SECTION.

METHODs m2.

ENDCLASS.

CLASS c2 IMPLEMENTATION.

METHOD m2.

CALL METHOD DELETE_ALL_MENUS.

ENDCLASS.

Here DELETE_ALL_MENUS is the protected method which is present in cl_gui_alv_grid..

I think it is useful for you.

Reward points if useful.

Thanks & regards

Deepika.

Read only

Former Member
0 Likes
692

thanq