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

Doubts in Data Declarations

prabhu_s2
Active Contributor
0 Likes
1,084

Hi Xperts

I'm posting this thread seeking for a clear clarification on the following and the impact in using them in our program:

1. <u><b>TYPE REF TO</b></u> VS <u><b>LIKE REF TO</b></u>

2. Use of <u><b>ANY</b></u> Vs <u><b>DATA</b></u>

kindly let me know how much difference it makes when making use of these

thkx

Prabhu

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,049

hi,

type ref to is used for user defined structures such as classes, objects...........

like ref to is used for ppredefined classes that are part of sap central library and also existing in r/3 server.

if helpful reward some points.

with regards,

Suresh Aluri.

11 REPLIES 11
Read only

Former Member
0 Likes
1,049

Hi,

<b>Reference Types</b>

You can define reference types locally in your programs or globally in the ABAP Dictionary. You use the following syntax:

TYPES <t> TYPE REF TO ...

After TYPE, there is no reference to an existing data type. Instead, the type constructor occurs:

The type constructor

REF TO DATA

declares a reference <t> to a data object. Fields with type <t> can contain references (pointers) to data objects, that is, instances of data types

The type constructor

REF TO <class>|<interface>

defines a reference type <t> to the class <class> or interface <interface>. Fields with type <t> can contain references (pointers) to instances of the class <class> or of classes that implement the interface <interface>

http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb30ea358411d1829f0000e829fbfe/content.htm

Regards

Sudheer

Read only

Former Member
0 Likes
1,049

Hi,

See following link :

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/4fbafc9e-0e01-0010-dea9-9d23d1b2...

Reward point if helpful.

Regards.

Srikanta Gope

Read only

Former Member
0 Likes
1,049

when you use type.... it means the

data variable1 type type1.

type1 is a type defined..

data var2 like variable1.

this is when the obj next to like exists as a global or local variable.. it can be defined in the existing program or it can be defined in the ddic..

Regards,

Aparna

Read only

0 Likes
1,049

yes aparna i'm aware of it but coming to sutuatins like the below :

data: item type ref to matnr.

vs

data: item type matnr.

what is the impact?

Read only

0 Likes
1,049

Hi...Prabhu.

Observe the Difference here.

To create a variable of type SY-DATUM use:

<b>DATA : V_DATE TYPE DATE.</b>

To Create a Reference variable which can store the address of a field with type

SY-DATUM use:

<b>DATA: R_DATE TYPE REF TO SY-DATUM.</b>

OR use:

<b>DATA: R_DATE LIKE REF TO V_DATE.</b>

Now you can use:

<b>GET REFERENCE OF V_DATE INTO R_DATE.</b>

That means R_date stores the Address of V_DATE.

If u give:

R_DATE->* = SY-DATUM.

WRITE:/ V_DATE.

The Value of V_DATE will be SY-DATUM.

<b>Reward if Helpful</b>

Read only

0 Likes
1,049

thakx narayana. u were right into it

Read only

prabhu_s2
Active Contributor
0 Likes
1,049

still not much clear. for instance take this example:

data: item type ref to matnr.

vs

data: item like ref to matnr.

in this sense what difference it makes? or i'm taking a irrelevant example?

Read only

Former Member
0 Likes
1,049

It is difficult to understand with that example..

matnr is the name given to both the data element and the fieldname in mara..

for example..

take the table tcurr goto se11 and see the table..

KURST is a field..

KURST_CURR is a data element..ie data type..

so i can say

data var1 type KURST_CURR

data var2 like tcurr-KURSt.

data var3 like var2.

Hope that helps u understand..

Regards,

Aparna

Read only

Former Member
0 Likes
1,049

data is a keyword used in abap for any data delerations

any is a type that can be used while defining variables wher u dont know which type they will be.. u can decide their type dynamically.. so in the begining you will define them as

data: var3 type any.

later u can type cast them..

Regards,

Aparna

Read only

Former Member
0 Likes
1,050

hi,

type ref to is used for user defined structures such as classes, objects...........

like ref to is used for ppredefined classes that are part of sap central library and also existing in r/3 server.

if helpful reward some points.

with regards,

Suresh Aluri.

Read only

prabhu_s2
Active Contributor
0 Likes
1,049

hmmm i have again opened th post as my second part still remains unawnsered.

2. Use of <u>ANY</u> Vs <u>DATA</u>