2006 Jul 20 6:52 PM
REPORT ZTUSH.
CLASS counter DEFINITION.
PUBLIC SECTION.
METHODS CONSTRUCTOR.
CLASS-METHODS: set IMPORTING value(set_value) TYPE i,
increment,
get EXPORTING value(get_value) TYPE i.
PRIVATE SECTION.
CLASS-DATA count TYPE i.
ENDCLASS.
METHOD CONSTRUCTOR.
WRITE:/ 'I AM CONSTRUCTOR DUDE'.
ENDMETHOD.
CLASS counter IMPLEMENTATION.
METHOD set.
count = set_value.
ENDMETHOD.
ENDCLASS.
DATA cnt TYPE REF TO counter.
START-OF-SELECTION.
CREATE OBJECT cnt.
CALL METHOD counter=>set EXPORTING set_value = number.
I THOUGHT WE CAN DEFINE CONSTRUCTOR METHOD OUTSIDE CLASS IMPLEMENTATION AS IN JAVA. But when I do that I get an error, method can be implemented only withing class. Why?
2006 Jul 20 6:56 PM
2006 Jul 20 8:21 PM
Hi Rajesh,
No you can not define CONSTRUCTOR METHOD OUTSIDE CLASS IMPLEMENTATION because in all public class the methods are defined in it events of our mouse defined in your local class such as :
data: editor TYPE REF TO cl_gui_textedit.
Here cl_gui_textedit is public class for editor when you dobleclick on it you see all methods.I think you just check that your container is not initial when loop run 1st time it will not getting value,Than please check your SET hendler.
Regards.
Ankur Garg.
Message was edited by: Ankur Garg
Message was edited by: Ankur Garg
2006 Oct 17 11:37 AM
Hello Rajesh
I do not fully understand what you mean by "I THOUGHT WE CAN DEFINE CONSTRUCTOR METHOD OUTSIDE CLASS IMPLEMENTATION AS IN JAVA". However, if you mean that we can create an object without having an explicit CONSTRUCTOR method defined then this is possible in ABAP like in Java (see coding below).
Regards
Uwe
REPORT ztush.
*---------------------------------------------------------------------*
* CLASS counter DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS counter DEFINITION.
PUBLIC SECTION.
*METHODS CONSTRUCTOR.
CLASS-METHODS: set IMPORTING value(set_value) TYPE i,
increment,
get EXPORTING value(get_value) TYPE i.
PRIVATE SECTION.
CLASS-DATA count TYPE i.
* NO explicit constructor
*METHOD CONSTRUCTOR.
*WRITE:/ 'I AM CONSTRUCTOR DUDE'.
*ENDMETHOD.
ENDCLASS. "counter DEFINITION
*---------------------------------------------------------------------*
* CLASS counter IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS counter IMPLEMENTATION.
METHOD set.
count = set_value.
ENDMETHOD. "set
METHOD get.
ENDMETHOD. "get
METHOD increment.
ENDMETHOD. "increment
ENDCLASS. "counter IMPLEMENTATION
DATA cnt TYPE REF TO counter.
START-OF-SELECTION.
* Implicit constructor is called
CREATE OBJECT cnt.
CALL METHOD counter=>set
EXPORTING
set_value = 5.
END-OF-SELECTION.