cancel
Showing results for 
Search instead for 
Did you mean: 

About Friend Method's and Friend attributes

Former Member
0 Kudos

Hi,

How to create Friend methods and Friend attributes for the class

Thanks and Regards

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

The specified object types (classes or interfaces) obj_type_1 ... obj_type_n are declared as friends of the current class. In this way, these object types and all the object types derived from these through inheritance, inclusion, and implementation are allowed to access PROTECTED and PRIVATE components, in addition to PUBLIC components. They can also create instances from the class, irrespective of the specifications in the CREATE addition. All classes and interfaces from the same program as well as global classes and interfaces from the class library can be specified as object types.

Note

If you define global classes and class library interfaces as friends, you should note that the local classes of other ABAP programs will not be visible in them. A static access to the componenents of the class class is not possible in such friends.

Example

interface I1.

...

endinterface.

class C1 definition create private friends I1.

private section.

data A1(10) type C value 'Class 1'.

endclass.

class C2 definition.

public section.

interfaces I1.

methods M2.

endclass.

class C2 implementation.

method M2.

data OREF type ref to C1.

create object OREF.

write OREF->A1.

endmethod.

endclass.

data OREF type ref to C2.

start-of-selection.

create object OREF.

OREF->M2( ).

In this excample, classs C2 is a friend of the interface

I1 and therefore of the implementing class C1. It can

instance these and also access their private components.

Addition 7

... GLOBAL FRIENDS publ_obj_type_1 ... publ_obj_type_n

Effect

This addition must be used only for the definition of global classes. It cannot, therefore be specified locally with the ABAP Editor in an ABAP program, but is automatically generated during the definition of a global class using the tool Class Builder of the ABAP workbench. The specified global object types (classes or interfaces) publ_obj_type_1 ... publ_obj_type_n are declared as friends of the current class. In this way, these objects and all the object types derived from these through inheritance, inclusion, and implementation are allowed to access PROTECTED and PRIVATE components, in addition to the PUBLIC components. They can also create instances from the class, irrespective of the specifications in the addition CREATE

Thanks,

Reward If Helpful.