‎2007 Oct 16 11:54 AM
‎2007 Oct 16 11:56 AM
hi
Refer this link
Re: LIKE & TYPE
Posted: Jul 23, 2007 6:18 AM in response to: Mohit Goel Reply
HI
1)
For TYPE
http://help.sap.com/saphelp_47x200/helpdata/en/d3/2e974d35c511d1829f0000e829fbfe/frameset.htm
For LIKE
http://help.sap.com/saphelp_47x200/helpdata/en/d3/2e974d35c511d1829f0000e829fbfe/frameset.htm
http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb367a358411d1829f0000e829fbfe/content.htm
LIKE means the datatype of the variable is similar to the referenced variable.
TYPE means it is a predefined data type.
Eg:
DATA int TYPE i.
Here int is of integer data type.
DATA var LIKE int.
var IS a variable having same data type of int. which in turn is integer.
You can find these helpful when you reference database table variables... You need not know what is the datatype defined.
Also it adds to FLEXIBILITY.
Whenever you make changes to your database tables and fields,
that change is REFLECTED back to your program that is,
You need not change all your program code when you change your table fields...
2)Passing the table using the TABLES parameters in a function module is one solution. However, using the IMPORT or CHANGING parameters is a better solution. Just create in the Dictionary a table type like your internal table to be able to TYPE your parameters.
<b>Reward point if you find this helpful</b>
Regards
Siva
‎2007 Oct 16 12:00 PM
The main difference between TYPE and LIKE parameter when defining or declaring the object is that TYPE is used to refer existing DATA TYPE (elementary or structured or user defined) while LIKE is used to declare data objects with reference to existing DATA OBJECTS.
For all practical purposes there are the same. The only additional advantage with types is that you can define your own types(including complex ones) in the data dictionary and reuse them accross various programs.
But within a program if two variables are defined one using LIKE and another using TYPE, both referring to the same field, then there is no difference.
If I include a type pool within a program, then I can define my variables only using TYPE to refer to any type defined in that pool. I cannot use LIKE in this scenario. Also, if I want to use native types like C, N, etc, I cannot use LIKE there either. I can use LIKE ABC only if ABC is in the database or if ABC is defined previously in the same program.
I can use TYPE ABC, if ABC is defined in database as a TYPE and included in the program with the statement TYPE-POOLS. I can use it, if it is the native types. I can use it, if it is already defined in the dictionary as a structure/table or structure/table field, or even if it is defined as a data element or a domain. So I can declare a variable V_BUKRS TYPE BUKRS, but I cannot define a variable V_BUKRS LIKE BUKRS.
But if I intend to use V_BUKRS to store company code, I will prefer to declare it as V_BUKRS LIKE T001-BUKRS, only because if tomorrow for some reason, the definition of T001-BUKRS changes to a data element for example, BUKRS_N(say DEC 4) instead of the data element BUKRS(CHAR 4) that it refers to now, I don't have to change my programs because I am referring to the table field and inhereting its properties. Whereas, had I declared my V_BUKRS TYPE BUKRS and the table now changed to BUKRS_N, I will be forced to change my program as there will be a type incompatability.
‎2007 Oct 16 11:57 AM
‎2007 Oct 16 11:58 AM
Hi,
Like Addition
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
LINE OF <table-object>
In this case, the LIKE addition describes the line type of a table object that is visible at that point in the program.
You use LIKE to make the new object or type inherit the technical attributes of an existing data object.
TYPE Addition
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.
Referring to Known Data Types
You can use the addition
TYPE <type>
to refer to any data type <type> that is already known at this point in the program. It can be used in any of the statements listed below. The expression <obj> is either the name of the data object or the expression
LINE OF <table-type>
In this case, the TYPE addition describes the line type of a table type <table-type> that is visible at that point in the program.
Thanks,
Reward If Helpful.
‎2007 Oct 16 11:59 AM
Refer the links -
http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb2ff3358411d1829f0000e829fbfe/content.htm
http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb2ff3358411d1829f0000e829fbfe/content.htm
LIKE is used inorder to refer to a present object and to have the semantic definition of that object that is being refered to.
TYPE is used in declaring the object using an elementary data type or a data element which has the same semantic definition that is required.
It is good practice to use TYPE as much as possible when there is a possibility to avoid LIKE.
TYPE
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.
LIKE
You use the LIKE addition, similarly to the TYPE addition , in various ABAP statements for defining data types and specifying the types of interface parameters or field symbols.
it 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.
The LIKE Addition:
You use the LIKE addition, similarly to the TYPE 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
LINE OF <table-object>
In this case, the LIKE addition describes the line type of a table object that is visible at that point in the program.
You use LIKE to make the new object or type inherit the technical attributes of an existing data object.
The TYPE Addition:
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.
Referring to Known Data Types You can use the addition
TYPE <type> to refer to any data type <type> that is already known at this point in the program. It can be used in any of the statements listed below. The expression <obj> is either the name of the data object or the expression
LINE OF <table-type> In this case, the TYPE addition describes the line type of a table type <table-type> that is visible at that point in the program.
use this links...
http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb2ff3358411d1829f0000e829fbfe/content.htm
for like....
http://help.sap.com/saphelp_nw04/helpdata/en/9b/239fa610de11d295390000e8353423/content.htm
‎2007 Oct 16 11:59 AM
The main difference between TYPE and LIKE parameter when defining or declaring the object is that TYPE is used to refer existing DATA TYPE (elementary or structured or user defined) while LIKE is used to declare data objects with reference to existing DATA OBJECTS.
For all practical purposes there are the same. The only additional advantage with types is that you can define your own types(including complex ones) in the data dictionary and reuse them accross various programs.
But within a program if two variables are defined one using LIKE and another using TYPE, both referring to the same field, then there is no difference.
If I include a type pool within a program, then I can define my variables only using TYPE to refer to any type defined in that pool. I cannot use LIKE in this scenario. Also, if I want to use native types like C, N, etc, I cannot use LIKE there either. I can use LIKE ABC only if ABC is in the database or if ABC is defined previously in the same program.
I can use TYPE ABC, if ABC is defined in database as a TYPE and included in the program with the statement TYPE-POOLS. I can use it, if it is the native types. I can use it, if it is already defined in the dictionary as a structure/table or structure/table field, or even if it is defined as a data element or a domain. So I can declare a variable V_BUKRS TYPE BUKRS, but I cannot define a variable V_BUKRS LIKE BUKRS.
But if I intend to use V_BUKRS to store company code, I will prefer to declare it as V_BUKRS LIKE T001-BUKRS, only because if tomorrow for some reason, the definition of T001-BUKRS changes to a data element for example, BUKRS_N(say DEC 4) instead of the data element BUKRS(CHAR 4) that it refers to now, I don't have to change my programs because I am referring to the table field and inhereting its properties. Whereas, had I declared my V_BUKRS TYPE BUKRS and the table now changed to BUKRS_N, I will be forced to change my program as there will be a type incompatability.
‎2007 Oct 16 12:00 PM
<b>TYPE f</b>
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 ,N ,D ,T ,X ,I ,P ,F ,STRING,XSTRING
<b>LIKE f</b>
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.
‎2007 Oct 16 12:00 PM
‎2007 Oct 16 12:01 PM
data: var type i,
var1 like var.
var is of type i and var1 is like var means it is aso of type i.
like is to refer the already defined variables.
type is to refer standard datatypes.
and with type declaration we can make user defined datatypes work like standard datatype in the report.
example:
<b>types: begin of typ_std,
sno typei,
sname(6),
end of typ-std.
data: it_std type table of typ_std,
wa_std like line of it_std.</b>
in the above we are deifing typ_std with types statement.
this means further in the program, any variable can be declared with type statement of that structure.
in the above it_std is an internal table type structure and wa_std is a work area like internal table.
i hope u r clear now.
‎2007 Oct 16 12:02 PM
Hi Subu..
TYPES: NAME(30) TYPE C. "User defined type
DATA : V_NAME1 <b>TYPE NAME . </b> While referring to a data type use TYPE
DATA : V_NAME1 <b>LIKE V_NAME1 . </b> While referring to a Variable use LIKE
Note: For DDIC Fields we can use both.
EG:
data : v_matnr like mara-matnr.
or
data : v_matnr type mara-matnr.
REWARD IF HELPFUL.