Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

internal table declaration

Former Member
0 Kudos

hai all,

DATA: ITAB TYPE TABLE OF MARA.

DATA: ITAB LIKE TABLE OF MARA.

WHAT IS THE BASIC DIFFERENCE BETWEEN THESE TWO COMMANDS.

THANKING U,

GOPAN

6 REPLIES 6

Former Member
0 Kudos

Hi gopan,

<b>In this case, there is no difference.</b>

1.

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.

2. try this code (just copy paste)

report abc.

types : char50(50) type c.

*----


type.

data : d1 type c, "--- native

d2 type n, "--- native

d25 type char50 , "----


User defined data type

d3 type bukrs, "---- data element / domain

d4 type persno, "---- data element / domain

d5 type t001, "---- table

d99 type c

.

data :

*l1 like c "----


Not Allowed

*l2 like n "----


Not Allowed

*l25 like char50 , "----


User defined data type

*l3 like bukrs "----


Not Allowed

*l4 like persno, "----


Not Allowed

l5 like t001 , "---- table

l99 like pa0001

.

regards,

amit m.

Former Member
0 Kudos

hi gopan!

see Type and Like both can use for predefined

where as like can use for userdefined only u can't use type here ok

example:

data: A type i or A like i. " it is correct

data: b type A. " error b'coz A is a user defined

the correct one is

data: b like A.

Former Member
0 Kudos

Hi,

Generally type is used for predefined objects and

like for userdefined

for ex...

if i say

data : a(2) type c

b(2) like a.

former_member927251
Active Contributor
0 Kudos

Hi Gopal,

There is no difference in this case but in general,

TYPE : you assign datatype directly to the data object while declaring.

LIKE : you assign the datatype of another object to the declaring data object. The datatype is referenced indirectly.

Reward points if it helps.

former_member184569
Active Contributor
0 Kudos

Hello Gopan,

TYPE is a keyword to refer data type.

LIKE is a keyword to refer data object.

data types are purely descriptive means no memory allocation.

data objects have memory allocation.

data types will define technical properties data objects.

Type will be faster than like due to the same reason.

Some long discussion on this in these forums too.

Thanks,

Susmitha

Former Member
0 Kudos

Hi,

According to your declaration, there is no difference.

You can learn the different betwen type and like in <a href="http://help.sap.com/saphelp_47x200/helpdata/en/fc/eb3605358411d1829f0000e829fbfe/frameset.htm">here</a>.

Regards,