on 01-06-2006 10:52 AM
Hi all,
What is the difference between
TYPE REF TO and
TYPE STANDARD TABLE OF
Thanks
Hi
- TYPE REF TO is used to declare a variable refered to certain class, so you use it if you want to program using OO.
DATA: MY_OBJECT TYPE REF TO <CLASS>.
- TYPE STANDARD TABLE OF is used to declare a internal table, this statamen is like:
BEGIN OF .... OCCURS n,
END OF ....
But it creates a table without header line, if you want the header line use WITH HEADER LINE options:
DATA: BEGIN OF T_BKPF OCCURS 0.
INCLUDE STRUCTURE BKPF.
END OF T_BKPF.
DATA: T_BKPF TYPE STANDARD TABLE OF BKPF WITH HEADER LINE.
These two stataments are similar.
Max
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Brunda,
<b>TYPES - REF TO</b>
Syntax
TYPES dtype { {TYPE REF TO type}
| {LIKE REF TO dobj} }.
Effect
The addition REF TO specifies a data type for a reference variable. The entry behind REF TO specifies the static type of the reference variable. The static type restricts the object quantity to which a reference variable can refer. The dynamic type of a reference variable is the data type and the object class to which it refers. The static type is always more general or the same as the dynamic type (see also Assignments Between Reference Variables).
You can use the TYPE addition to define data types for data and object reference variables. You can only define data types for data reference variables with the LIKE addition.
Data References
If, for type, you have specified the predefined generic data type data, the system creates a data type for a data reference variable from the static type data. Such reference variables can refer to any data objects but can only be dereferenced in the statement ASSIGN.
If, for type, you have specified any non-generic data type (a non-generic data type from the ABAP Dictionary), a non-generic program-local type already defined with TYPES, or a non-generic predefined type (d, f, i, string, t, xstring), the system creates a data type for a data reference variable with the relevant static type. Such reference variables can refer to all data objects of the same type and can be dereferenced to matching operand positions using the dereferencing operator ->*.
If, for dobj, you have specified a data object of the same program, the system creates a data type for a data reference variable whose static type is adopted from the data type of the data object. Such reference variables can refer to all data objects of the same type and can be dereferenced to matching operand positions using the dereferencing operator ->*. Within a procedure, you cannot specify a generic typed formal parameter for dobj.
Object References
If, for type, you have specified a global or local class, the system creates a data type for a class reference variable whose static type is the specified class. Such reference variables can refer to all instances of the class and its subclasses. You can access all components of an object with a class reference. If the static type is the super class of the dynamic type, then the components that can be statically called are a subset of the components of the dynamic type. You can call all attributes and methods of a dynamic type using a class references and the dynamic object attribute call (see ASSIGN) and the dynamic method call (see CALL METHOD).
If, for type, you have specified a global or local interface, the system creates a date type for an interface reference variable whose static type is the specified class. Such reference variables can refer to objects of all classes that implement the interface. When calling components of objects with interface references, the name of the static type is always implicitly placed before the component. With an interface reference, you can only access the interface components of an object that are known in the static type. This applies for the dynamic and the static call.
Example
This example shows how data types are defined for an interface reference and for a class reference as well as a data reference to an interface reference.
INTERFACE i1.
...
ENDINTERFACE.
CLASS c1 DEFINITION.
PUBLIC SECTION.
INTERFACES i1.
ENDCLASS.
TYPES: iref TYPE REF TO i1,
cref TYPE REF TO c1,
dref TYPE REF TO iref.
And ,
<b>TYPE STANDARD TABLE OF xxxx WITH HEADER LINE</b> is used to define an internal table in which each row is of the structure xxxx:
Regards,
Raj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Brunda,
1. Though both are defined using TYPE,
the main difference is :
Ref to : It REFERS to (Points to something)
Standard Table of : True variable/data having
its own memory space.
2. eg
DATA : cont TYPE REF TO cl_gui_custom_container.
data : myitab type standard table of t001.
3. cont is just like a POINTER.
myitab is a variable/internal table
having its own memory space.
regards,
amit m.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
TYPE REF TO is used ABAP Objects to create the instance of a class.
data: o_obj type ref to cl_gui_alv_grid.
type standarad table of is used to create the internal table .
data: itab type standard table of mara.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Type ref to is used to create the instance of a class where as type table of is used to define the table of another one.
rgds
p.kp
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Brunda,
Let me make a point clear here. TYPE STANDARD TABLE OF is used for internal tables. By definition when you have TYPE in DATA this creates a variable while it executes your progam but when you use TYPE REF TO it only creates a reference variable.
The difference between them is variable is a area where value can be stored while the program executes but a reference variiable is one which holds the address of a data object created. For example, instance of a class is created and the address of the instance is stored in a reference variable. when you access any attributes it actually refers the instance and gets the value.
<b> We can use TYPE REF TO also for a generic data type called data and also for a generic instance reference called object.</b> If you see there is neither a datatype called data or a class called object. Here when you say
DATA l_ref TYPE REF TO data.
CREATE DATA l_ref TYPE <something>
It creates a variable or an object of this type and l_ref just points to it. Hope I answered your query.
Regards,
Srikanth
User | Count |
---|---|
84 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.