‎2007 Jul 27 5:43 AM
hi
i am trying oops in ABAP .can any body correct this code below.
CLASS c_counter DEFINITION.
PUBLIC SECTION.
METHODS: set_counter IMPORTING value(set_value) TYPE i,
increment_counter,
get_counter EXPORTING value(get_value) TYPE i.
data count type i.
ENDCLASS. "C_COUNTER DEFINITION
----
CLASS C_COUNTER IMPLEMENTATION
----
*
----
CLASS c_counter IMPLEMENTATION.
METHOD set_counter.
count = 0.
ENDMETHOD. "SET_COUNTER
METHOD increment_counter.
DO 10 TIMES.
count = count + 1.
ENDDO.
ENDMETHOD. "INCREMENT_COUNTER
METHOD get_counter.
WRITE count.
ENDMETHOD. "GET_COUNTER
ENDCLASS. "C_COUNTER IMPLEMENTATION
DATA: obj1 TYPE REF TO c_counter.
call method obj1-> set_counter
importing
set_value = 0.
‎2007 Jul 27 5:55 AM
HI,
Problem solved check the code and the comments,
You need to put this code in a report program.
ANd for a report program to start exection you need
START-OF-SELECTION event block.
THen you need to create the object before you can call the method.
SO use CREATE OBJECT.
Then you need to EXPORT not IMPORT parameter, since you will be exporting the data to the method. when you declare the method as IMPORTING data when you call the method you need to use EXPORTING.
CLASS c_counter DEFINITION.
PUBLIC SECTION.
METHODS: set_counter IMPORTING value(set_value) TYPE i,
increment_counter,
get_counter EXPORTING value(get_value) TYPE i.
DATA count TYPE i.
ENDCLASS. "C_COUNTER DEFINITION
*----------------------------------------------------------------------*
* CLASS C_COUNTER IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS c_counter IMPLEMENTATION.
METHOD set_counter.
count = 0.
ENDMETHOD. "SET_COUNTER
METHOD increment_counter.
DO 10 TIMES.
count = count + 1.
ENDDO.
ENDMETHOD. "INCREMENT_COUNTER
METHOD get_counter.
WRITE count.
ENDMETHOD. "GET_COUNTER
ENDCLASS. "C_COUNTER IMPLEMENTATION
START-OF-SELECTION. "Need thisevent in report to start execution
DATA: obj1 TYPE REF TO c_counter.
CREATE OBJECT obj1." Need to create object
CALL METHOD obj1->set_counter
EXPORTING "Need to use Exporting not IMPORTING
set_value = 0.
Regards,
Sesh
‎2007 Jul 27 5:46 AM
What is the error you are getting ? Please mention it here.
Regards,
Manoj
‎2007 Jul 27 5:55 AM
HI,
Problem solved check the code and the comments,
You need to put this code in a report program.
ANd for a report program to start exection you need
START-OF-SELECTION event block.
THen you need to create the object before you can call the method.
SO use CREATE OBJECT.
Then you need to EXPORT not IMPORT parameter, since you will be exporting the data to the method. when you declare the method as IMPORTING data when you call the method you need to use EXPORTING.
CLASS c_counter DEFINITION.
PUBLIC SECTION.
METHODS: set_counter IMPORTING value(set_value) TYPE i,
increment_counter,
get_counter EXPORTING value(get_value) TYPE i.
DATA count TYPE i.
ENDCLASS. "C_COUNTER DEFINITION
*----------------------------------------------------------------------*
* CLASS C_COUNTER IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS c_counter IMPLEMENTATION.
METHOD set_counter.
count = 0.
ENDMETHOD. "SET_COUNTER
METHOD increment_counter.
DO 10 TIMES.
count = count + 1.
ENDDO.
ENDMETHOD. "INCREMENT_COUNTER
METHOD get_counter.
WRITE count.
ENDMETHOD. "GET_COUNTER
ENDCLASS. "C_COUNTER IMPLEMENTATION
START-OF-SELECTION. "Need thisevent in report to start execution
DATA: obj1 TYPE REF TO c_counter.
CREATE OBJECT obj1." Need to create object
CALL METHOD obj1->set_counter
EXPORTING "Need to use Exporting not IMPORTING
set_value = 0.
Regards,
Sesh