‎2007 Mar 28 6:52 AM
Dear all experts,
I am bw certified, learning abap at my own,
I have gone thr. sams abap in 21 days. still i am having some confusions.
1) Can anybody please tell exact difference of using LIKE and TYPE in case of tables
I am getting confused, exactly what to use and when to use.
Is there any relation to work area, of above point ?
How these are concerned to with header and without header.
2) how to pass internal table to routines and function ?
can you give any example or link to example, showing difference between, pass by value, refrence and value & result.
Surely, points will be assigned to your appropriate help.
Waiting....
regards....
Vinay.
‎2007 Mar 28 6:56 AM
Hi Vinay,
http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb2ff3358411d1829f0000e829fbfe/content.htm
ABAP distinguishes between types and objects. Types are descriptions that do not occupy memory. Objects are instances of types, and do occupy their own memory space. A type describes the technical attributes of all of the objects with that type.
You can use the addition
TYPE <type>
to refer to any data type <type> that is already known at this point in the program.
DATA <f> TYPE <type>.
The data object <f> has a data type corresponding to the type <type>.
DATA <f> LIKE <obj>.
The data object <f> inherits all of the technical attributes of the data object <obj>.
Rgds,
Prakash
‎2007 Mar 28 6:56 AM
Hi Vinay,
http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb2ff3358411d1829f0000e829fbfe/content.htm
ABAP distinguishes between types and objects. Types are descriptions that do not occupy memory. Objects are instances of types, and do occupy their own memory space. A type describes the technical attributes of all of the objects with that type.
You can use the addition
TYPE <type>
to refer to any data type <type> that is already known at this point in the program.
DATA <f> TYPE <type>.
The data object <f> has a data type corresponding to the type <type>.
DATA <f> LIKE <obj>.
The data object <f> inherits all of the technical attributes of the data object <obj>.
Rgds,
Prakash
‎2007 Mar 28 6:59 AM
Hi Vinay,
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.
Regards,
Priyanka.
‎2007 Mar 28 6:59 AM
Hi..
Try these links..
http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb2ff3358411d1829f0000e829fbfe/frameset.htm
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
If u need about more difference means .. Search in the forums ..
Regards
bala..
‎2007 Mar 28 7:00 AM
1')
Like is used when:
Build internal table and work area from existing internal table
Type:
Build internal table and work area from existing DDIC structures
Chk the link below for more info:
http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb35de358411d1829f0000e829fbfe/content.htm
‎2007 Mar 28 7:03 AM
if you have declared some field as a data in your program and then you are declaring another field depending on this field.
e.g.
types: pernrs type char8.
data: pernr1 type pernrs.
data: pernr2 like pernr1.
here you are declaring pernrs on a data type pernrs.
pernr1 is declared on a type pernrs.
and pernr2 is declared on pernr1. hence we use like.
you cannot use pernrs directly as a variable.
regards,
Manish
rewards are helpful
‎2007 Mar 28 7:03 AM
hi vinay,
the difference between in type and like is :
when defining or declaring the object is that type is used to refer existing data type.
while like is used to declare data objects with reference to existing data objects.
type is mostly used for defining a new object.
for ur second question, u can find a chapter in the 21 days book itself under the chapter modularization techniques. Kindly go thro that one. u can get a clear picture from that.
Regards....
Arun.
Reward points if useful.
‎2007 Mar 28 7:07 AM
Hi Vinay ,
Regarding part 1 of your question , i still have not yet found a satisfactory answer for it till now , so now what i do is to use TYPE where ever possible becasue that is recommended , one issue i find with like is that we do not refer to the data type directly but we refer to a feild in the data base table.
e.g. Data : v_matnr like matnr . " does not work.
we need to write Data : v_matnr like mara-matnr.
Regarding relation to work area , i dont think it has any effect on the work area.
same goes with header and without header lines , the reason why internal table wihtout header lines is recommended is that it is better in performance and this is also not allowed in ABAP Objects.
Regarding Q 2.
Here is a sample code which answers the question
tables : mara.
Types : begin of ty_marc ,
matnr type matnr ,
werks type werks_d ,
flag type c ,
end of ty_marc.
data : it_1 type table of ty_marc ,
wa_1 type ty_marc.
select-options : so_matnr for mara-matnr .
start-of-selection.
select matnr werks
into table it_1
from marc
where matnr in so_matnr.
perform set_flag changing it_1.
write 'test'.
*&---------------------------------------------------------------------*
*& Form set_flag
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_IT_1 text
*----------------------------------------------------------------------*
form set_flag changing value(p_it_1) type table . " Pass by value
loop at p_it_1 into wa_1.
wa_1-flag = 'X'.
modify p_it_1 from wa_1.
endloop.
endform. " set_flagdebugg the program and see after the first records is modified the content of the table it_1 and p_it_1 in both call by ref and call by value.
in case you have any further queries please feel free to revert back.
Regards
Arun
‎2007 Mar 28 7:08 AM
there is no as such difference in TYPE and LIKE statement.
you use like statement when u define local veriable with DATA statement.
It has no relation to work area.
2) when you pass internal table to routine then at the formal parameter you have to collect it with type statement
e.g.
form abc using itab type itab.
endform.
and in case of FM there are two type of parameter TABLES and CHANGING . Now a days SAP recomends to use CHANGING paramentr insted of TABL parament.
suppose a1 = 10.
i) pass by vale.
perform sub a1.
form sub using b1.
b1 = 20.
endform.
after completion of FORM the value of a1 will be 10.
ii) pass by ref.
perform sub a1.
form sub changing b1.
b1 = 20.
endform.
the value of a1 will be 20 as soon as b1 gets 20..
iii) pass by value result
perform sub a1.
form sub using value b1.
b1 = 20.
endform.
after succesful completion of FORM the value of a1 will be 20.
reward is useful.
Kapil Soni