‎2007 Jun 30 5:50 PM
Hello
while declaring data we use statement
TYPE , FOR ,LIKE
Please tell me the diff between them
with regards
‎2007 Jun 30 5:53 PM
Hi,
TYPE - Type is used to tell the system what is the type of data object(variable) you want to create .
LIKE: If there is already a data object declared and you want to declare a similar data object you can just refer to the previous data object using like.
Rewards
Aneesh.
‎2007 Jun 30 5:53 PM
Hi,
TYPE - Type is used to tell the system what is the type of data object(variable) you want to create .
LIKE: If there is already a data object declared and you want to declare a similar data object you can just refer to the previous data object using like.
Rewards
Aneesh.
‎2007 Jul 02 11:06 AM
Not similar. Identical.
Use LIKE e.g. when you declare a local copy of a parameter to a form. As far as I know SAP's recommendation is now to use LIKE when you want to ensure and indicate (to later program maintainers) that a data object is identical in type to another data object. The main point being that they are not <i>accidentally</i> the same data type, it is deliberate (and thus usually important so you don't want things to change if someone changes the referred data object).
For everything else you should use TYPE, also in function module parameters. Previously you were forced to use LIKE for some of the function module parameters.
FOR is not used to declare data, only to declare selection screen parameters (ranges).
‎2007 Jun 30 7:49 PM
hi,
<b>TYPE</b>
You use the TYPE addition in various ABAP statements for defining data types and specifying the types of interface parameters or field symbols. The TYPE addition can have various meanings depending on the syntax and context.
<b>LIKE</b>
You use the LIKE addition, similarly to the TYP E addition , in various ABAP statements for defining data types and specifying the types of interface parameters or field symbols. The addition
LIKE <obj>
can be used in the same ABAP statements as the TYPE addition to refer to any data object <obj> that is already visible at that point in the program. The expression <obj> is either the name of the data object or the expression.
You use LIKE to make the new object or type inherit the technical attributes of an existing data object.
<b>FOR</b>
We use FOR statement for processing the selection table.
regards,
Ashok reddy
‎2007 Jul 02 11:10 AM
Hi,
Check this SAP help :
... TYPE REF TO type
Defining a typed data reference variable. Types you can use include elementary types, types defined using TYPES, or types created in the ABAP Dictionary. You can dereference completely typed data reference variables using the dereferencing operator ->* at any operand position.
Example
types:
LNTYP type I.
data:
CNT type ref to I,
LINE type ref to LNTYP,
FLIGHT type ref to SFLIGHT.
create data CNT.
create data LINE.
create data FLIGHT.
CNT->* = 20.
LINE->* = 110.
FLIGHT->FLDATE = SY-DATUM.
... TYPE type
Effect
The field f is created with type type. For the type, you can specify either one of the predefined types listed below, a type defined using the TYPES statement, or a type created in the ABAP Dictionary.
The standard length ( SL ) of a field depends on its type.
Type Explanation SL Initial value
C Text (Character) 1 space
N Numeric text 1 '00...0'
D Date (YYYYMMDD) 8 '00000000'
T Time (HHMMSS) 6 '000000'
X Hexadecimal (HeX code) 1 X'00'
I Integer 4 0
P Packed number 8 0
F Floating point number 8 0
STRING Character sequence (string) variable-length empty string
XSTRING Byte sequence (X string)
variable-length empty hexadecimal string
Example
DATA NUMBER TYPE I.
DATA WA_SPFLI TYPE SPFLI.
The field NUMBER is created with type I. You can now use it in the program. In particular, you can assign numeric values to the field and use it in calculations ( ABAP number types).
The field WA_SPFLI is created using the type of the database table SPFLI from the ABAP Dictionary. This field is structured and can be used especially for working with data from database table SPFLI.
... LIKE f1
The syntax check performed in an ABAP Objects context is stricter than in other ABAP areas.
See Cannot Use LIKE References to Dictionary Types.
Effect
Field f is created with the same field attribtues as the data object f1, which has already been declared. Any data object (field, parameter, structure...) is allowed as long as its type has been fully specified.
f1 can be any ABAP Dictionary reference.
Example
DATA TABLE_INDEX LIKE SY-TABIX.
The field TABLE_INDEX now has the same attributes as SY-TABIX (index field for internal tables).
Note
You should use this addition whenever you can. If the type of a field to which you are referring changes, the ABAP runtime system updates all references automatically. It also stops the system from carrying out unnecessry (and maybe undesirable) type conversions.
FOR
We use FOR statement for processing the selection table.
Regards
Message was edited by:
skk
‎2007 Jul 02 12:43 PM
Hi, Basavraj
<b>TYPE</b> : it will allocate memory during execution (object type).
<b>Type will improve performance.</b>
When we want to create a data object of an existing data type we use TYPE
E.g. DATA gv_var1 TYPE i. Create a data object of type integer.
TYPES When u want to create a data type and not an object.
TYPES : ty_int TYPE i. ty_int is an integer type
<b>LIKE</b> : it will allocate memory immediately.
When we declare a variable, with reference to some object in memory, we use LIKE.
When we have a data object and u want to create a similar data object.
E.g.DATA gv_var2 LIKE gv_var1. gv_var2 is an integer like gv_var1.
Whenever you need any internal table in your program which should have same fields as in a database table, we can declare the internal table
Using LIKE addition.
DATA gt_itab LIKE <dbtab> WITH HEADER LINE.
But like addition is not recommended as a coding standard, and so is WITH HEADER LINE addition.
‎2007 Jul 06 5:33 AM
LIKE only describes the characteristics of that field type.(default memory not allocated and cant store default values )
Type does the same and also we can store default values using type (ie....Default memory is allocated when we use type )
Reward if useful. and close the thread.
‎2007 Jul 06 6:38 AM
in the program, then in the ABAP Dictionary for a database table or flat structure with the same name. You can no longer use this kind of type reference in ABAP Objects classes. You should also avoid using the LIKE addition in other ABAP programs except to refer to data objects. To refer to data types, you should use the TYPE addition instead.
reward points if it is usefull ..
Girish