2008 Jul 01 8:58 AM
Hello!
I have created a new class:
CALL METHOD me->say
receiving
say_me = a
.
write: a.
And abap says, "me" is not defined. How/where can I define it? I am a beginner....
Thanks!
2008 Jul 01 9:15 AM
Hi,
you need to create reference of the class.
then you can use that refernce to call the method.
here 'me' is the reference variable.
to create reference variable..
ex:-
CREATE OBJECT me.
data: me type ref to <class name>.
call method me-><methodname>...
Regards,
venkat N
Hi,
you need to create reference of the class.
then you can use that refernce to call the method.
here 'me' is the reference variable.
to create reference variable..
ex:-
CREATE OBJECT me.
data: me type ref to <class name>.
call method me-><methodname>...
Regards,
venkat N
2008 Jul 01 9:12 AM
Before implementing a class u need to define it.
See the demo program below.
REPORT demo_class_counter .
CLASS counter DEFINITION.
PUBLIC SECTION.
METHODS: set IMPORTING value(set_value) TYPE i,
increment,
get EXPORTING value(get_value) TYPE i.
PRIVATE SECTION.
DATA count TYPE i.
ENDCLASS.
CLASS counter IMPLEMENTATION.
METHOD set.
count = set_value.
ENDMETHOD.
METHOD increment.
ADD 1 TO count.
ENDMETHOD.
METHOD get.
get_value = count.
ENDMETHOD.
ENDCLASS.
DATA number TYPE i VALUE 5.
DATA cnt TYPE REF TO counter.
START-OF-SELECTION.
CREATE OBJECT cnt.
CALL METHOD cnt->set EXPORTING set_value = number.
DO 3 TIMES.
CALL METHOD cnt->increment.
ENDDO.
CALL METHOD cnt->get IMPORTING get_value = number.
WRITE number.
Regards,
Jagadish
2008 Jul 01 9:15 AM
Hi,
you need to create reference of the class.
then you can use that refernce to call the method.
here 'me' is the reference variable.
to create reference variable..
ex:-
CREATE OBJECT me.
data: me type ref to <class name>.
call method me-><methodname>...
Regards,
venkat N
2008 Jul 01 9:19 AM
Hi,
Please check the below...
A method can have a variable defined within it having the same name as one of the attributes of the class to which the method belongs to. To clearly identify the class level attribute, the selector ME is used. Check the below code...
class testclass definition.
public section.
data : i_num type i value 5.
methods : testmethod .
endclass.
class testclass implementation.
method :testmethod.
data : i_num type i value 2.
write:/5 me->i_num , "access variable of the class
/5 i_num . " access variable of the method
endmethod.
endclass.
start-of-selection.
data : i_num type i.
data : my_obj type ref to testclass.
create object : my_obj.
call method my_obj->testmethod.
Rgds,
Bujji
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |