Application Development and Automation 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: 
Read only

internal table

Former Member
0 Likes
640

hello,

1. what is the difference between TYPE and LIKE,

explai with example please.

2.what is the difference between internal table and work area.

6 REPLIES 6
Read only

Former Member
0 Likes
590

Hi Shashi,

In simple,

TYPE stmt is to create another user-defined data type whereas,LIKE stmt is to create variable.

WORKAREA is just like structure which can carry one record at a time whereas,INTERNAL TABLE is like a table which can store any no. of records.Records wil be available only at runtime.Lifetime of INTERNAL TABLE is within that program where internal table is declared and wont be stored as global.

Reward points if useful

Regards,

kamalapriya

Read only

Former Member
0 Likes
590

Hi,

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>.

Take an example :

types : begin of ty_tab,

name(30),

pwd(10),

end of ty_tab.

data : itab like ty_tab.

See here we declared the structure of ty_tab, which do not occupy memory. So if we run this, we will get compile time error like this : Field TY_TAB is unknown. It is neither in one of the specified tables nor defined by a DATA statement.

So in this case u need to correct the error with "TYPE" statement...like this.

types : begin of ty_tab,

name(30),

pwd(10),

end of ty_tab.

data : itab type ty_tab.

Refer these

http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb2ff3358411d1829f0000e829fbfe/content.htm

http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb2ff3358411d1829f0000e829fbfe/content.htm

Internal table: can hold any number of records.

Workarea : can hold only one record.

When we are passing the records internal table work area is compulsory

Read only

Former Member
0 Likes
590

Hi

in internal table ..at run time all the records will be stored where as in workarea there will be only one record.

already defined dattypes we use TYPE.

parameter : C type C.

TYPE there is no memory allocated.

LIKE is used for already declared data objects.

LIKE memory will be allocated.

Read only

Former Member
0 Likes
590

hi,

TYPE addition

With TYPE addition, you can refer either to local data types of the same ABAP program or on global data types of the Dictionaries.

Local types mask global types that have the same names. When typing the interface parameters or field symbols, a reference is also

possible to generic types ANY, ANY TABLE,INDEX TABLE, TABLE or STANDARD TABLE, SORTED TABLE and HASHED TABLE.

The LIKE addition

With the LIKE addition, you can refer to all visible data objects

at the ABAP program's positon in question. Only the declaration of the data object must be known. In this case it is totally irrelevant whether the data object already exists physically in memory during the LIKE reference. Local data objects mask global data objects that have the same name.

The semantic separation between data types and data objects is reflected by the syntactic separation in ABAP between TYPE and LIKE.

This separation allows for separate namespaces for data types and data objects. Only for reasons of compatibility with preceding releases

Hope this helps, Do reward.

Read only

Former Member
0 Likes
590

difference type and like

Answer1:

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.

Answer2:

Type is a keyword used to refer to a data type whereas Like is a keyword used to copy the existing properties of already existing data object.

Answer3:

type refers the existing data type

like refers the existing data object

diff between internal table and work area

workarea

While adding or retrieving records to / from internal table we have to keep the record temporarily.

The area where this record is kept is called as work area for the internal table. The area must have the same structure as that of internal table. An internal table consists of a body and an optional header line

internal table

You can define internal tables either with (WITH HEADER LINE addition) or without header lines.

An internal table with header line consists of a work area (header line) and the actual table body. You address both objects

using the same name. The way in which the system interprets the name depends on the context. For example, the MOVE statement applies to the header line, but the SEARCH statement applies to the body of the table.

To avoid confusion, you are recommended to use internal tables without header lines. This is particularly important when you use nested tables. However, internal tables with header line do offer a shorter syntax in several statements

( APPEND, INSERT, MODIFY, COLLECT, DELETE, READ, LOOP ).

Within ABAP Objects, you can only use internal tables without a header line. You can always address the body of an internal table <itab> explicitly by using the following syntax: <itab>[]. This syntax is always valid, whether the internal table has a header line or not.

Example

DATA itab1 TYPE TABLE OF i WITH HEADER LINE.

DATA itab2 TYPE TABLE OF i WITH HEADER LINE.

itab1 = itab2.

" Only header lines will be copied

itab1[] = itab2[].

" Copies table body

hope this is helpful! do reward

Read only

Former Member
0 Likes
590

Hi,

To process a record of the internal table a work area is a must. To process the record of the internal table, we move each record of table in to work area and check, is it the right record to process and again modify the internal table from work area.

That is for processing internal table, work area is a must. work area will hold a single record.

type is used to define the variable from defined types.

no memory is allocated.

like is used to define the variable from already defined variable.

it will in herit all the properties. and a memory is allocated.

regards,

kamala.