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

create object vs create data statements

Former Member
0 Likes
2,534

Hi,

   please, explain me the deference between the create object and create data statements in abap programming.

Regards,

Krishna.

9 REPLIES 9
Read only

Former Member
0 Likes
1,670

This message was moderated.

Read only

0 Likes
1,670

Hi hasan,

               Thanks for your reply.i have gone through the links .

                my doubt is that,in create object  the definition in like :-

                CREATE DATA allows you to create fields in a pre-defined or user-defined data type .(the same we can achieve by using the types and data statements . ) .

                      can you please , explain me in detail .


Regards,

Krishna.

Read only

0 Likes
1,670

using   CREATE DATA we can define something that is already declared.

like

FIELD-SYMBOLS: <WA>   TYPE ANY.

   DATA: WA_REF TYPE REF TO DATA.

  CREATE DATA WA_REF TYPE (TAB_NAME).


but using types or data we can define anything new..

data : farid type c.



Read only

Former Member
0 Likes
1,670

do one thing..

just write two lines..

CREATE DATA krishna TYPE C.

DATA krishna TYPE C.

& now check your program,

Read only

0 Likes
1,670

Hi farid hasan,

                      i got the conceptual definition now.thanks for sharing .and i did the sample code provided in the bc-aba document in my ides and executed and the program is terminated with a short dump ."OBJECTS_NOT_FLAT" at the select query ,below is the code for your reference ,

REPORT ZSA_SAMPLE.

PARAMETERS:

tab_name like sy-tname ,

tab_comp like X031L-TABNAME ,

nls type i default 10 .

FIELD-SYMBOLS : <lfs_dtab> TYPE ANY ,<lfs_dcomp>  .

DATA : wa_ref TYPE REF TO data .

CREATE DATA wa_ref TYPE REF TO (tab_name) .

ASSIGN wa_ref->* to <lfs_dtab> .

SELECT * FROM (tab_name) INTO <lfs_dtab> UP TO nls ROWS.

   WRITE :/ tab_comp,<lfs_dcomp>.

   ENDSELECT .


               And i changed it to

ASSIGN wa_ref->* to <lfs_dcomp> .

SELECT * FROM (tab_name) INTO <lfs_dcomp> UP TO nls ROWS.

then it is terminating with "TARGET AREA IS TOO SMALL" dump.

             do u have any idea about this short dump.

thanks ,

krishna.

Read only

Former Member
0 Likes
1,670

Create Object is used to create data object of user define type i.e, nothing but the class. And Create Data is used to create data object of predefined type like char, decimal, integer, structure,internal table.

Let say you have a class lcl_demo_class.

Then if you want to create a data object of type "lcl_demo_class" then you have to use create object as follows.

Data: obj type ref to lcl_demo_class. "Declaration of the reference. Please mark that data object

                                                      " is not created of type lcl_demo_class.

CREAT OBJECT obj.

and Create Data is used to create a data object of predefined type( c,i,d,p etc). It creates a data object dynamically.

data: obj type c.

create data c.

It will create a data object dynamically of type c.

Create Data do the same as the DATA. It will create a data of predefined type. Create Data is mainly used in RTTS(RunTime Type Services).

RTTS is used to create data type dynamically. Please mark, RTTS is used to define data type dynamically, not data object.

After defining the data type dynamically through RTTS, when you need to create data object of that type, then you need CREATE DATA.

Let me know if you have any doubt on this.

Thanks.

Gourab

Read only

0 Likes
1,670

Thankq gourab,thanks for your explanation .

regards,

krishna .

Read only

former_member219762
Contributor
0 Likes
1,670

Hi,

Create Object creates reference to Object( which is runtime instance of class).

Create Data creates reference to Data(which is other than class and interface).

We can access object attributes by objectreference->attribute

but we cannot access data with data reference,we should dereferenced it to get value

datareference->*

Regards,

Sreenivas.

Read only

0 Likes
1,670

Hi sreenivas,

                 Thanks for sharing .

thanks,

krishna .