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: 

basic

Former Member
0 Kudos

Hi,

anybody will tell me what is the difference b/w

itab type zstr

and

itab like zstr.

where zstr is my structure.

9 REPLIES 9

Former Member
0 Kudos

Hi salil,

1. In your case, it will give error

for TYPE,

2. bcos zstr is a data which has been declared,

and LIKE expects data,

and TYPE expects some type, and not some data.

3.

report abc.

data : zstr like t001.

*----


will give error

*data : itab type zstr.

*----


OK

data : mytab like zstr.

regards,

amit m.

0 Kudos

hi Salil,

In your case you have to use a <b>Like</b> statement

Check this thread out to know the difference

<b>TYPE</b> is a keyword to refer data type.

<b>LIKE</b> 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.

Regards,

santosh

former_member188685
Active Contributor
0 Kudos

Hi,

<b>data: test like ztest. "it will give error

data: test type Ztest. "it will not give any error</b>

Regards

vijay

Former Member
0 Kudos

Hi,

Normally,we use TYPE to refer any datatypes and LIKE for any object.

here you have 2 options to create an internal table

either by refering any datatype or

by any dataobject.

1)

if you define structure like ,

types : begin of str1,

f1 type c,

end of str1.

*--this above definition is just a declaration of

*--structure not an OBJECT.

if you are defining internal table you should use TYPE

data : itab type str1 occurs 0 with header line.

Because, you defined a structure type(not an Object), so while creating internal table , you should use TYPE,

2)

data : begin of str1,

f1 type c,

end of str1.

data : itab like str1 occurs 0 with header line.

here we used LIKE in the definition of ITAB because we are refering an existing object(structure).

Regards

srikanth

Message was edited by: Srikanth Kidambi

Message was edited by: Srikanth Kidambi

Former Member
0 Kudos

Hi Salil,

Same question, refer to this link.

Regards,

Arun Sambargi.

0 Kudos

If we declare

p_one like pa0001-pernr

p_two type pa0001-pernr

both p_one and p_two will refer the datatype of the field...

so here.. LIKE & TYPE are alike no ???

.......Am i right

Same scenario in....

p_one TYPE persno

p_two LIKE persno

Former Member
0 Kudos

Hi,

when U r refering to a object then use LIKE and

when to TYPES instance then use type .

Regards

vikas

0 Kudos

Hi,

Thats OK.

But if i use TYPE declaration to a object, that also works fine,

Eg. p_pernr TYPE pa0001-pernr

Can anybody explain this...

0 Kudos

Hi Anbarasan,

<b>ABAP Data Types and Data Objects</b>

Programs work with local data in the program. Data is a sequence of bytes in the memory of the program. Each sequence of bytes that belongs together is called a field, and each field has a length, an identifier (name), and a data type. All programming languages have a concept that explains how the contents of a field (the sequence of bytes) is interpreted according to the particular data types in that language.

Within the ABAP type concept, fields are known as data objects. A data object is an instance of an abstract data type. Consequently, data types can occur not only as the attributes of a field, but also as a standalone type definition. Data types and data object have separate namespaces. This means that a data object and a data type can both have the same name, even though they are separate entities. The same visibility rules apply to both data types and data objects: Locally-defined types and objects obscure global types and objects with the same names.

The ABAP type concept ensures that the type information belonging to a data object is inseparably joined to it. The syntax check, program generator, and runtime environment always have full type information for every data object.

When you create data objcets and specify the types of formal parameters and field symbols, you can refer to a data type (either directly or indirectly):

<b>Using ... TYPE dataType</b> - the data type dataType is addressed directly.

<b>Using ... LIKE dataObject</b> - the type of data object dataObject is addressed indirectly.

If <b>dataObject</b> has the type dataType, the indirect reference using ... LIKE <b>dataObject</b> is exactly the same as the direct reference using ... TYPE dataType, that is, ... LIKE <b>dataObject</b> adopts all of the type information of dataObject.

At runtime, the inseperable link between data types and data objects means that all type-dependent operations can access full type information, even where programs use untyped parameters and field symbols.

Refer to this link to get the further Information.

<a href="http://help.sap.com/saphelp_di471/helpdata/EN/fc/eb2fb2358411d1829f0000e829fbfe/content.htm">Data Types and Data Objects</a>

Regards,

Arun Sambargi.

Message was edited by: Arun Sambargi