Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Object Creation in abap

Former Member
0 Likes
1,594

hi all greetings.

i came a across a line of code in ABAP.

<code>DATA:    lr_intf TYPE REF TO lif_test,
         lr_mine TYPE REF TO lcl_myclass.
<code>CREATE OBJECT lr_intf TYPE lcl_myclass.<br>

here lif_test is an i nterface.

My question is that how exactly object is getting created by TYPE keyword in here using the lcl_myclass.

1 ACCEPTED SOLUTION
Read only

1,413

I will try to answer your question using how memory is allocated.

So when you write following code-

CLASS c1 DEFINITION.  ... ENDCLASS. 
DATA oref TYPE REF TO c1.  
CREATE OBJECT oref. 

So in above code we are creating reference to variable oref for class c1 and then we are allocating the memory.

CLASS c1 DEFINITION. 
....
ENDCLASS. 

DATA oref TYPE REF TO object. 

CREATE OBJECT oref TYPE c1. 

And in above code we are creating reference to variable object and then we are defining class and allocating the memory.

Hope this will help you.

For more queries you can refer

Create Object

hi all greetings.

i came a across a line of code in ABAP.

<code>DATA:    lr_intf TYPE REF TO lif_test,
         lr_mine TYPE REF TO lcl_myclass.
<code>CREATE OBJECT lr_intf TYPE lcl_myclass.<br>

here lif_test is an i nterface.

My question is that how exactly object is getting created by TYPE keyword in here using the lcl_myclass.

3 REPLIES 3
Read only

DoanManhQuynh
Active Contributor
0 Likes
1,413

i dont really understand what do you want to know with this question but you could press F1 on the CREATE OBJECT to read how it work.

Read only

Muthu_raja
Active Participant
0 Likes
1,413

Even I don't understand whether you are asking how "create object type" syntax is working or how it is creating object for an interface.

If it is an second doubt, then we can't create an object for an interface unless it is implemented in the class. If you check your lcl_myclass, it must implemented the interface lif_test.

Read only

1,414

I will try to answer your question using how memory is allocated.

So when you write following code-

CLASS c1 DEFINITION.  ... ENDCLASS. 
DATA oref TYPE REF TO c1.  
CREATE OBJECT oref. 

So in above code we are creating reference to variable oref for class c1 and then we are allocating the memory.

CLASS c1 DEFINITION. 
....
ENDCLASS. 

DATA oref TYPE REF TO object. 

CREATE OBJECT oref TYPE c1. 

And in above code we are creating reference to variable object and then we are defining class and allocating the memory.

Hope this will help you.

For more queries you can refer

Create Object