08-20-2007 1:15 PM
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
08-20-2007 1:29 PM
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.
08-20-2007 1:19 PM
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
08-20-2007 1:20 PM
Hi,
See following link :
Reward point if helpful.
Regards.
Srikanta Gope
08-20-2007 1:23 PM
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
08-20-2007 1:26 PM
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?
08-20-2007 1:39 PM
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>
08-20-2007 1:45 PM
08-20-2007 1:24 PM
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?
08-20-2007 1:30 PM
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
08-20-2007 1:25 PM
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
08-20-2007 1:29 PM
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.
08-20-2007 1:54 PM
hmmm i have again opened th post as my second part still remains unawnsered.
2. Use of <u>ANY</u> Vs <u>DATA</u>