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
Request clarification before answering.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
> 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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.