cancel
Showing results for 
Search instead for 
Did you mean: 

reg : CREATE PRIVATE PUBLIC PROTECTED

07-16-2008 8:55 AM
1705 views 5 comments Go to solution
0 Likes
SAP Managed Tags
Subscribe

Hi Frnz,

I am new to this topic can anyone help me on the follwing with an example please

I need examples please

Its F1 help

A class with the CREATE PUBLIC addition can be instantiated anywhere that the class is visible.

A class with the CREATE PROTECTED addition can only be instantiated in methods of the class itself and its subclasses.

A class with the CREATE PRIVATE addition can only be instantiated in methods of the class itself. This means, in particular, that it cannot be instantiated as an inherited component of subclasses

please donot paste from sites

regards

0 Likes

Accepted Solutions (1)

Accepted Solutions (1)

uwe_schieferstein
Active Contributor
0 Likes

Hello

In this case their must be a static public method around to instantiate such a class => FACTORY method or class.

Example:

CL_RECA_MESSAGE_LIST (instantiation protected, friend class CF_RECA_OBJECT)

Factory class CF_RECA_MESSAGE_LIST (sub-class of CF_RECA_OBJECT).

Static method CREATE is used to instantiate CL_RECA_MESSAGE_LIST.

Note: This is an ABAP specific realization (friend concept).

Regards

Uwe

Former Member
0 Likes

hi frnz

can anyone provide a general example

not that much related to abap

Answers (2)

Answers (2)

Former Member
0 Likes

Hi,

you can check the following code:

REPORT Z_oops.

" Class cls definition----


CLASS cls DEFINITION.

PUBLIC SECTION.

METHODS:

add IMPORTING

im_var1 TYPE i

im_var2 TYPE i,

display.

PRIVATE SECTION.

DATA:

w_var1 TYPE i,

w_var2 TYPE i,

w_result TYPE i.

ENDCLASS. "cls DEFINITION

" Class cls implementation----


CLASS cls IMPLEMENTATION.

METHOD add.

w_var1 = im_var1.

w_var2 = im_var2.

w_result = im_var1 + im_var2.

ENDMETHOD. "add

METHOD display.

WRITE:

/ w_var1,'+',w_var2,'=',w_result.

ENDMETHOD. "display

ENDCLASS. "cls IMPLEMENTATION

*" Data declaration

PARAMETERS:

p_var1 TYPE i,

p_var2 TYPE i.

DATA:

ref1 TYPE REF TO cls.

START-OF-SELECTION.

CREATE OBJECT ref1.

ref1->add( im_var1 = p_var1

im_var2 = p_var2 ).

and tutorial better ref to:

saptechnical.com-> tutorials-> Object Oriented programming

Regards,

Anirban

Former Member
0 Likes

hi,

I think you did not understand my question

its addition for the stateemnt class definition

class c1 definition create public/private/protected.

<code>

endclass.

could you help please

matt
Active Contributor
0 Likes

> A class with the CREATE PUBLIC addition can be instantiated anywhere that the class is visible.

Most classes you'll ever see

>

> A class with the CREATE PROTECTED addition can only be instantiated in methods of the class itself and its subclasses.

>

>

> A class with the CREATE PRIVATE addition can only be instantiated in methods of the class itself. This means, in particular, that it cannot be instantiated as an inherited component of subclasses

>

Read up on the factory pattern at, e.g. wikipedia.