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

Former Member
0 Kudos

Hi Gurus,

1.Can i know the exact differenct b/w internal table and Structure

2. What are the types of internal tables?

3. how we declare internal table .. i.e..

if i declare like -- data: begin of itab,

fields,

endof itab.

is that be a internal table or structure ? why?

What is the use of with header line ?

Thanx & Regards,

Srinath

1 ACCEPTED SOLUTION

Former Member
0 Kudos

1. Can i know the exact differenct b/w internal table and Structure

Ans: INTERNAL TABLE : IS AN RUNTIME OBJECT WHICH STORES THE DATA TEMPORARILY. THAT MEANS WHEN U RUN THE REPORT IT STORES THE DATA IN THE INTERNAL TABLE AND WHEN U COME OUT OF THE REPORT, INTERNAL TABLE DOES NOT STORE THE DATA THAT MEANS IT IS DEAD.

STRUCTURE : A STRUCTURE CONSISTS OF ONLY ONE ROW .IT DOES NOT STORE THE DATA .

NO PRIMARY KEY OPTION

NO TECHNICAL SETTINGS IT IS USED LKE SKELETON THAT MEANS STRUCTURE.

2. What are the types of internal tables?

Ans : There 3 types of i-tab.

standard i-table,

sorted i-table

hashed i-table

3. how we declare internal table .. i.e..

if i declare like -- data: begin of itab,

fields,

endof itab.

is that be a internal table or structure ? why?

ans : i think it is strucuture bcos u dint write the occurs statement after the itab which is used as memory to store data.

4 : What is the use of with header line ?

in order to c the output we should send the data from body to header line .

14 REPLIES 14

Former Member
0 Kudos

Hi,

internal table is work area which is temporarly created and specfic to the program but structure can be combination of one or more table which when created is stored on the database and can be reused ...

Internal Tables are Three Types ,

Sorted,Hashed And Standard.


Iif i declare like -- data: begin of itab,
fields,
endof itab.

The Above codes Declare wa,not internal table Because,

For Creating a internal table you have three different Parameters.

1. Table kind.

2. Line type,

3. Key fields.

So if you want the internal table then you need to Declare it like below,

Data:

itab_tab like standard table of itab.

Now this will create an internal table with the structure type itab.

The optional addition WITH HEADER LINE declares an extra data object with the same name and line type as the internal table. This data object is known as the header line of the internal table. You use it as a work area when working with the internal table (see Using the Header Line as a Work Area). When you use internal tables with header lines, you must remember that the header line and the body of the table have the same name. If you have an internal table with header line and you want to address the body of the table, you must indicate this by placing brackets after the table name (itab[]). Otherwise, ABAP interprets the name as the name of the header line and not of the body of the table. You can avoid this potential confusion by using internal tables without header lines. In particular, internal tables nested in structures or other internal tables must not have a header line, since this can lead to ambiguous expressions.

For Deatil you Can refer these like-

http://help.sap.com/saphelp_nw70/helpdata/en/fc/eb36a1358411d1829f0000e829fbfe/content.htm

http://www.sap-img.com/abap/with-header-without-header-internal-table.htm

http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb35de358411d1829f0000e829fbfe/content.htm

Regards,

Sujit

Former Member
0 Kudos

Hi Srinath,

Check these links which provide complete information on internal tables:

http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb35de358411d1829f0000e829fbfe/content.htm

http://www.sap-img.com/ab009.htm

Check this link for differnt type of internal tables:

http://www.sap-img.com/abap/what-are-different-types-of-internal-tables-and-their-usage.htm

Hope this helps you.

Regards,

Chandra Sekhar

Former Member

naveen_inuganti2
Active Contributor
0 Kudos

Hi....

The code you written is for internal table....

Here header line is nothing but work area of that internal table...we can handle header line seperately in the program...

Internal table = Header line + Body

There will be some memory allocates for internal table in aplication server...

This memory will deallocates when you came back from that program or if you write FREE ITAB sytax in your program memory will deallocates after the list display...

We can create structures also from programs... with TYPES syntax...

Internal table can acts as database table in runtime.. but not Structure....

Thanks,

Naveen.I

0 Kudos

Hi Naveen,

data: begin of itab,

fields,

endof itab.

this code is for internal table ok. then what is the use of occurs ?

can i use the same code as structure , if so can i work on structure like storing data, selecting data & reading data from that.

Then what is the exact difference b/w internal table & Structure? When shud i use which one?

Regards,

Srinath

Former Member
0 Kudos

Hi,

see the details..

Internal Tables - Overview

What Are Internal Tables?

Internal tables are a way to store datasets of a fixed structure in the working memory of ABAP. The data is stored on a row-by-row basis, where each row has the same structure. The individual components of a row are also referred to as the columns of the internal table.

There are two kinds of internal tables in ABAP: data types and data objects. A data type returns the abstract description of an internal table and is used to create concrete data objects.

Data Types

Structures and internal tables represent the two structured data types available in ABAP (see ABAP Type Concept). The data type of an internal table is fully specified by:

Row type

The row type of an internal table can be any ABAP data type (that is, it can also be an internal table).

Key

The key is used to identify table rows. There are two possible keys for internal tables, the standard key and a user-defined key. The key can be defined as unique (UNIQUE) or non-unique (NON-UNIQUE). If a key is unique, no multiple entries exist in internal tables. The uniqueness depends on the table type (see below).

The standard key is made up of all non-numeric components of the associated row type that are no internal tables themselves or do not contain internal tables.

The user-defined key can be made up of any components that are no internal tables themselves or do not contain internal tables, that is, do not have a deep structured type. Internal tables with a user-defined key are called key tables. When you define the key, you must pay attention to the order of the key fields, which is important, for example, for sorting the data based on the key.

Table type

The table type determines how ABAP accesses individual table rows. Based on the table type, internal tables can be subdivided into the following three categories:

In standard tables, a logical index is set up internally. The data can be accessed using the table index or the key. If the data is accessed using the key, the response time depends linearly on the number of table entries. The key of a standard table is always non-unique. When you define the table, you must not specify uniqueness for the key.

Sorted tables are always stored sorted by the key. Also for sorted tables, a logical index is set up internally. The data can be accessed using the table index or the key. If the data is accessed using the key, the response time depends logarithmically on the number of table entries since the data is accessed through a binary search. The key of sorted tables can be unique or non-unique. When you define the table, you must specify whether the key is UNIQUE or NON-UNIQUE.

Standard tables and sorted tables are also commonly referred to as index tables.

In hash tables, no logical index is set up internally. Hash tables can only be accessed by specifying the key. The response time in this case is constant irrespective of the number of table entries since the data is accessed through a hash algorithm. The key of hash tables must be unique. When you define the table, you must specify the key as UNIQUE.

Unlike other user-defined ABAP data types, the data type of an internal table does not need to be fully specified but can be set up generically. This means that if you create a data type for an internal table, you can either leave the key or the row type and the key unspecified.

Data Objects

Data objects created with the data type of an internal table or directly as an internal table are always specified fully with regard to row type, key, and table type. However, they can have any number of rows. Internal tables are consequently dynamic data objects that can contain any number of rows of a fixed type. The number of rows of an internal table is only restricted by the capacity limits of the actual system installation. The row types of internal tables are any ABAP data types and can therefore be elementary, structured, or internal tables themselves. The individual rows of an internal table are called table rows or table entries.

Using Internal Tables

Internal tables offer the functionality of dynamic arrays in ABAP and free the programmer from having to control dynamic memory management in the program. Internal tables are generally used if datasets of a fixed structure are processed internally in the program, for example, if contents of database tables are stored and edited internally in the program. Internal tables are also the most important means to implement highly complex data structures in an ABAP program.

Data Exchange with Internal Tables

There are two ways to handle internal tables. You can either address the entire internal table data object, also called the table body, or you can address individual table entries.

If you access the entire table body, you can use the table name like an elementary field in appropriate ABAP statements such as MOVE and execute the corresponding operation for the entire data object.

When accessing individual table entries, you do not directly operate on the data in the table but use another data object as the work area. The work area is used as an interface to the entries of the internal table and must be at least convertible into the row type of the internal table. Usually, however, you use work areas of the same data type as the rows of the internal table. When data is read from table rows, the contents of the work area are overwritten with the contents of the table row addressed. The contents of the work area can then be used in the program. When data is written into table rows, you must first enter the data into the work area. The system then transfers the data from the work area into the table row.

You can create internal tables with a line known as a header line, which has the same data type as a table row. The header line can be used as the table work area. This table work area and the internal table itself have the same name. ABAP statements for accessing individual table entries can implicitly use the header line as the work area. In ABAP statements that do not implicitly access the entire table body, you must distinguish the work area from the header line by adding angle brackets after the name (for example itab[]). The reason for this is that the system generally interprets the name in such statements as the name of the work area and not as the internal table. So that the table can be distinguished from the work area, you should create internal tables without header lines, if possible. In particular, internal tables must not have header lines if they are part of structures or other internal tables since this would result in ambiguous expressions.

Operations on Internal Tables

When individual table entries are accessed, the following table operations are common:

Filling using the ABAP statements:

INSERT

APPEND

COLLECT

Reading using the ABAP statements:

READ

LOOP

Modifying using the ABAP statement:

MODIFY

Deleting using the ABAP statement:

DELETE

Which ABAP statement you use depends on the table type of the internal table. While you use the APPEND statement to fill a standard table, you use INSERT for filling hash tables. Besides these statements, there is a set of generic operations that can be applied to any kind of table. These generic operations are as follows:

INSERT ... INTO TABLE ...

MODIFY TABLE ...

READ TABLE ... [FROM ...|WITH TABLE KEY ...]

DELETE TABLE ... [FROM ...|WITH TABLE KEY ...]

These statements are valid for all table types and are executed by the system in a type-adequate manner for each table.

Selecting a Table Type

Which table type you choose for an individual table depends on how the above mentioned typical operations on individual table entries are applied to the table most frequently.

Standard tables:

Use this table type if the individual entries are addressed through an index Index-based access is the quickest way to access table entries. You should fill standard tables by appending rows ( APPEND), and read, modify and delete them using an index (INDEX addition of the relevant ABAP statement). The response time for key-based access to standard tables increases linearly with the number of table entries. If key-based access is necessary, it makes particular sense to use standard tables if filling the table can be isolated from the other processing steps. For example, you can fill a standard table by appending rows and sort it afterwards. If you then use key-based access with the option for binary search (BINARY SEARCH addition), the response time depends only logarithmically on the number of the table entries.

Sorted tables

You use this table type if the table must be available in sorted form when it is set up. The table is then filled by inserting rows ( INSERT ... INTO TABLE) based on the sort order defined by the table key. The response time for key-based access depends logarithmically on the number of table entries, since a binary search is performed automatically. Sorted tables are also particularly useful for the partially sequential processing of a LOOP loop if the first parts of the table key are specified in the WHERE condition.

Hash tables

You use this table type if key-based access constitutes the central operation on table entries. Index-based access to hash tables is not possible. The response time for key-based access is always constant and does not depend on the number of table entries. As with database tables, the key of hash tables is always unique. Hash tables can therefore also be used to set up database-type internal tables and use them accordingly.

Declaring Internal Tables

Like any other ABAP data object, internal tables can first be created as a data type ( TYPES statement) and subsequently as a data object, or they can be directly declared as a fully specified data object ( DATAstatement). When you create an internal table as a data object, bear in mind that this only declares the administrative entry for an internal table as static. Unlike with all other ABAP data objects, the size of the memory space required is, however, not yet determined. The actual table rows are dynamically generated at runtime through operational fill statements and removed through delete statements.

When declaring an internal table, you can control the memory requirements of the table using the OCCURS and INITIALSIZE additions. This may affect the response times for filling the internal table (see the Performance Notes for Internal Tables).

Internal Tables as Parameters for Routines

Like any other parameter, internal tables can be passed to subroutines and function modules by value or by reference.

If you want to pass a table together with its header line to a subroutine, you must pass it by reference using the TABLES addition. However, only STANDARDtables are allowed as TABLES parameters.

If a STANDARD table without a header line is passed as an actual parameter to a formal parameter with a header line (TABLES), the system automatically creates a header line in the routine. If you want to pass the body of a table with a header line as an actual parameter to a formal parameter without a header line, however, you can do this by using angle brackets after the name as described above.

hope it will help..

Former Member
0 Kudos

Hi srinath,

Let me clear your doubt one by one.

1. internel tables are created in the programming itself and the data are read from the application level. Internel tables of one program cant be used in other programs. But structures once you create you can use it again and again.

There are theree types of structure:-

A. Flat structure( elementry fields)

B. Nested structure ( type reference to other structure)

C. deep structure ( type reference to database tables)

2. Internal tables are of 3 types:

Standard

Sorted

Hashed

3. Here you have declare a structure.

if you want to declare an standard internal table with this structure as work area

Syntax will be

data:

itab like

standard table

of (structure name)

Regards,

Anirban

Former Member
0 Kudos

Hi

With Regards

Nikunj Shah

Former Member
0 Kudos

This message was moderated.

Former Member
0 Kudos

1. Can i know the exact differenct b/w internal table and Structure

Ans: INTERNAL TABLE : IS AN RUNTIME OBJECT WHICH STORES THE DATA TEMPORARILY. THAT MEANS WHEN U RUN THE REPORT IT STORES THE DATA IN THE INTERNAL TABLE AND WHEN U COME OUT OF THE REPORT, INTERNAL TABLE DOES NOT STORE THE DATA THAT MEANS IT IS DEAD.

STRUCTURE : A STRUCTURE CONSISTS OF ONLY ONE ROW .IT DOES NOT STORE THE DATA .

NO PRIMARY KEY OPTION

NO TECHNICAL SETTINGS IT IS USED LKE SKELETON THAT MEANS STRUCTURE.

2. What are the types of internal tables?

Ans : There 3 types of i-tab.

standard i-table,

sorted i-table

hashed i-table

3. how we declare internal table .. i.e..

if i declare like -- data: begin of itab,

fields,

endof itab.

is that be a internal table or structure ? why?

ans : i think it is strucuture bcos u dint write the occurs statement after the itab which is used as memory to store data.

4 : What is the use of with header line ?

in order to c the output we should send the data from body to header line .

Former Member
0 Kudos

Thanx to all.

Former Member
0 Kudos

Hi,

Internal table is basically used if you want to use only some fields of a

standard SAP table.

a structure is defined if you want to use fields of different tables as per

your requirements.

An internal table with a header line creates a work area for the internal table

that you have created.

Internal Tables

Internal tables provide a means of taking data from a fixed structure and

storing it in working memory in ABAP. The data is stored line by line in memory,

and each line has the same structure. In ABAP, internal tables fulfill the function

of arrays. Since they are dynamic data objects, they save the programmer the task of

dynamic memory management in his or her programs. You should use internal tables

whenever you want to process a dataset with a fixed structure within a program.

A particularly important use for internal tables is for storing and formatting data

from a database table within a program. They are also a good way of including very

complicated data structures in an ABAP program.

*Structures*

A structure is a sequence of any other data types from the ABAP Dictionary, that is, data elements, structures, table types, or database tables. When you create a structure in the ABAP Dictionary, each component must have a name and a data type.

In an ABAP program, you can use the TYPEaddition to refer directly to a structure.

If you define a local data type in a program by referring to a structure as follows:

TYPES dtype TYPE structure.

the construction blueprint of the structure is used to create a local structure dtype in the program. The predefined Dictionary data types of the domains used by the data elements in the structure are converted into the corresponding ABAP types. The semantic attributes of the data elements are used for the corresponding components of the structure in the program. The components of the local structure dtype have the same names as those of the structure in the ABAP Dictionary.

You can refer the following links:

http://help.sap.com/erp2005_ehp_03/helpdata/EN/fc/eb34d0358411d1829f0000e829fbfe/frameset.htm

http://help.sap.com/erp2005_ehp_03/helpdata/EN/fc/eb34d0358411d1829f0000e829fbfe/frameset.htm

Thanks and Regards,

Manish