Assigning object reference and creating objects in ABAP

Go down

Assigning object reference and creating objects in ABAP

Post  Admin on Sat Mar 31, 2012 11:18 pm


As we know objects are runtime replica of classes ,they are real runtime entities of the
class, and come into picture during program execution. Objects occupy memory space .

An object cannot exist by itself it must have a class reference ,every object has the class
reference stored in a variable ,and we call it object name ,with the help of this reference we
can access the class components . Lets see how we can do it .

DATA: my_obj_ref TYPE REF TO ref_class_name.
The TYPE REF TO statement helps us to assign the object reference .
Objects can be created using CREATE OBJECT statement.
CREATE OBJECT: my_obj_ref.


Code:
 CLASS test DEFINITION.
PUBLIC SECTION.
METHODS test_method.
ENDCLASS.
CLASS test IMPLEMENTATION.
METHOD test_method.
WRITE:/ ‘this is my method’.
ENDMETHOD.
ENDCLASS.
*************** main program **************
START-OF-SELECTION.
DATA: obj_ref TYPE REF TO test. “ object reference is assigned
CREATE OBJECT: obj_ref. “ object is created
CALL METHOD Obj_ref->test_method. “object method is called using the reference.

Admin
Admin

Posts : 92
Join date : 2012-01-26

http://mysaplab.forumotion.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum