‎2009 May 06 7:49 AM
Hello experts!
I have created a class and now I want to inplement in my program how should I do this.
‎2009 May 06 7:52 AM
Hi,
please be more specific ...
have you created methods without implementing them in the class. and you want them to implement in program...
or you have implemented the methods and you want to use the class in your program...
Regards,
Siddarth
‎2009 May 06 7:57 AM
hello Sidharth,
I have implemented the methods and I want to use the class in My program.
‎2009 May 06 8:06 AM
First declare a reference object in the program for that class type
say for example you have created a class cl_test
now declare the object...
data : w_obj type ref to cl_test.now press ctrl+F6 from keyboard and select the second radio button (ABAP Object Pattern ) then hit enter...
now select the second radio button create object,
and in the instance type w_obj and for class type cl_test and then hit enter.
this will create object for the class you have created and then you can call methods or use attributes of that class in your program using this object.....
to call a method do the following
press ctrl+F6 and then select second radio button and then select the first radio button call method and in instance give w_obj and for class give cl_test and give the method name you want to call....
and then hit enter...
to uxse any attribute you can do it this way....
w_obj->attrib1.
Hope this is helpful...
Regards,
Siddarth
‎2009 May 06 8:39 AM
please refer the below example..
----
CLASS c3 DEFINITION
----
CLASS c3 DEFINITION.
PUBLIC SECTION.
DATA: var1 TYPE matnr VALUE 'LAPTOP'.
METHODS: m1 IMPORTING imp TYPE i
RETURNING value(ret1) TYPE i.
PRIVATE SECTION.
DATA: var2 TYPE i VALUE 134.
ENDCLASS. "c3 DEFINITION
----
CLASS c3 IMPLEMENTATION
----
CLASS c3 IMPLEMENTATION.
METHOD m1.
WRITE:/'Initial values the M1 method'.
WRITE: / 'IMP:',imp.
WRITE:/ 'RETURN:',ret1.
WRITE:/'Values after manipulation in the M1 method'.
ret1 = imp + 100.
WRITE:/ 'RETURN:',ret1.
WRITE:/ 'Private var2:',var2.
ENDMETHOD. "m1
ENDCLASS. "c3 IMPLEMENTATION
----
START-OF-SELECTION
----
START-OF-SELECTION.
DATA: cvar TYPE i VALUE 99,
evar TYPE i,
evar1 TYPE i.
DATA:obj1 TYPE REF TO c3.
CREATE OBJECT obj1.
*Accessing the class attributes
WRITE:/ '(var1)MATERIAL:',obj1->var1.
CALL METHOD obj1->m1
EXPORTING
imp = 20
RECEIVING
ret1 = evar.
WRITE:/'Values after the call method M1'.
WRITE:/'RETURN:',evar.
‎2009 May 07 1:52 PM
Please note that according to the rules of engagement, if answers have been useful, you should award points to those people who have helped you. Failure to do this can lead to your account being deleted.
Matt