Assigning object reference and creating objects in ABAP
Page 1 of 1
Assigning object reference and creating objects in ABAP
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.
Similar topics
» Object Lifetime and event in ABAP Objects
» Creating multiple Objects in ABAP Objects
» Creating Interface in ABAP Objects with example
» Creating multilevel inheritance in ABAP Objects
» Creating classic reports in ABAP Objects
» Creating multiple Objects in ABAP Objects
» Creating Interface in ABAP Objects with example
» Creating multilevel inheritance in ABAP Objects
» Creating classic reports in ABAP Objects
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|
Mon Aug 20, 2012 4:37 pm by Admin
» Difference between Type and Like
Thu Jun 07, 2012 2:40 pm by Admin
» How to handle table control fields in Module Pool program?
Wed May 09, 2012 2:41 am by govind
» Three tables inner join in SAP
Thu May 03, 2012 4:47 pm by Uma_ABAP
» Creating table type in ABAP
Sat Apr 28, 2012 9:03 pm by Uma_ABAP
» Creating user defined types and structures in ABAP
Sat Apr 28, 2012 8:55 pm by Uma_ABAP
» Creating Dynamic Internal Table and Dynamic Field catalog in SAP-ABAP
Fri Apr 27, 2012 11:00 am by Admin
» Copy Custom PF-Status from Standard program to Custom Program in ALV
Thu Apr 26, 2012 9:52 pm by Uma_ABAP
» Calculate/find number of working days between two dates in SAP
Tue Apr 24, 2012 2:06 pm by Uma_ABAP