07-03-2006 1:02 PM
Hello Every1,
I have created a implementaion for some definition.
Now I need to call a method from the implemenation in my program. Let me know how to call it?
Regards,
Siva.
07-03-2006 1:05 PM
1. Create the instance of the class.
CREATE OBJECT C1. (If there are any parameters to the constructor of the method you will have to pass here.
2. Now call the method
CALL METHOD C1-->METHOD1. (Pass the parameters).
You can do this using the pattern of the ABAP Editor also.
If its a static class, you can directly call the method without instantiating the class
Regards,
Ravi
note : Please mark the helpful answers
Message was edited by: Ravikumar Allampallam
07-03-2006 1:05 PM
1. Create the instance of the class.
CREATE OBJECT C1. (If there are any parameters to the constructor of the method you will have to pass here.
2. Now call the method
CALL METHOD C1-->METHOD1. (Pass the parameters).
You can do this using the pattern of the ABAP Editor also.
If its a static class, you can directly call the method without instantiating the class
Regards,
Ravi
note : Please mark the helpful answers
Message was edited by: Ravikumar Allampallam
07-03-2006 1:05 PM
Hi,
You need to create a instance of the class and call the method using the syntax CALL METHOD instance_name->method_name if the method is an instance method.
For static methods you need to use the syntax CALL METHOD class_name=>method_name
-Kiran
07-03-2006 1:11 PM
Hi sivaprakash pandian ,
If u want to call the method of same class in the mplementation of another method,just u need to use CALL METHOD METHOD_NAME, other wise if u want to call the method of other class, u have create the object of that class and with that obj, uneed to call the method,
i.e,
CREATE OBJECT OBJ.
CALL METHOD OBJ->METH1.
Regards,
kiran B
07-03-2006 1:13 PM
Hi Siva,
Check the ABAPDOCU transaction. And go through this program....
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.
Hope it helps u in some way.
07-03-2006 1:21 PM
Hai
Go through the following Code
&----
*& Report ZABAPOBJECTS_01 *
*& *
&----
*& *
*& *
&----
report ZABAPOBJECTS_01 .
parameter : p_matnr like mara-matnr.
----
CLASS lcl_material DEFINITION
----
*
----
class lcl_material definition.
public section.
data: v_matnr type mara-matnr.
methods : constructor importing matnr type mara-matnr,
get_material_description.
private section.
data : v_maktx type makt-maktx.
endclass. "lcl_material DEFINITION
----
CLASS lcl_material IMPLEMENTATION
----
*
----
class lcl_material implementation.
method get_material_description.
clear v_maktx.
select single maktx into v_maktx
from makt
where matnr = v_matnr and
spras = 'E'.
endmethod. "get_material_description
method constructor.
clear v_matnr.
v_matnr = matnr.
endmethod. "constructor
endclass. "lcl_material IMPLEMENTATION
data : obj type ref to lcl_material.
start-of-selection.
create object obj exporting matnr = p_matnr.
call method obj->get_material_description.
Thanks & regards
Sreenivasulu P
07-03-2006 1:28 PM
data: c1 TYPE REF TO object.
CREATE OBJECT c1 TYPE class.
create method c1 type method