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

VB09104
Active Participant
0 Kudos

hello all,

what is difference betn standard internal tables, sorted internal tables and hashed internal tables?

how do we define these tables in ABAP report

thanks

vikas

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

These are the three types of internal tables.

STANDARD table

Key access to a standard table uses a linear search. This means that the time required for a search is in linear relation to the number of table entries.

You should use index operations to access standard tables.

SORTED table

Defines the table as one that is always saved correctly sorted.

Key access to a sorted table uses a binary key. If the key is not unique, the system takes the entry with the lowest index. The runtime required for key access is logarithmically related to the number of table entries.

HASHED table

Defines the table as one that is managed with an internal hash procedure

You can only access a hashed table using the generic key operations or other generic operations ( SORT, LOOP, and so on). Explicit or implicit index operations (such as LOOP ... FROM oe INSERT itab within a LOOP) are not allowed.

follow this link for more information on internal tables type........

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

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

Thanks.

Reawrd If Helpful.

5 REPLIES 5

Former Member
0 Kudos

Hi,

These are the three types of internal tables.

STANDARD table

Key access to a standard table uses a linear search. This means that the time required for a search is in linear relation to the number of table entries.

You should use index operations to access standard tables.

SORTED table

Defines the table as one that is always saved correctly sorted.

Key access to a sorted table uses a binary key. If the key is not unique, the system takes the entry with the lowest index. The runtime required for key access is logarithmically related to the number of table entries.

HASHED table

Defines the table as one that is managed with an internal hash procedure

You can only access a hashed table using the generic key operations or other generic operations ( SORT, LOOP, and so on). Explicit or implicit index operations (such as LOOP ... FROM oe INSERT itab within a LOOP) are not allowed.

follow this link for more information on internal tables type........

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

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

Thanks.

Reawrd If Helpful.

abdulazeez12
Active Contributor
0 Kudos

Internal tables are holds the data which is having the same structure and storing it in working memory in ABAP. The data is stored line by line in the memory. The main purpose of internal table is for storing and formatting data from a database table within a program. It is used to minimize the DB access time in report programs.

Internal table are dynamic data objects, since they can contain any number of lines of a particular type. The maximum memory that can be occupied by an internal table (including its internal administration) is 2 gigabytes.

Types of Internal Tables :

1. Standard Internal Tables :

Standard tables have an internal linear index. The system can access records either by using the table index or the key. The response time for key access is proportional to the number of entries in the table. This means that standard tables can always be filled very quickly, since the system does not have to check whether there are already existing entries. WE can fill a standard table by appending lines (ABAP APPEND statement), and read, modify and delete entries by specifying the index (INDEX option with the relevant ABAP command).

2. Sorted tables :

Sorted tables are always saved sorted by the key. They also have an internal index. The system can access records either by using the table index or the key. The response time for key access is logarithmically proportional to the number of table entries, since the system uses a binary search. Entries are inserted according to the sort sequence defined through the table key.

3. Hashed tables :

Hashed tables have no linear index. You can only access a hashed table using its key. The response time is independent of the number of table entries, and is constant, since the system access the table entries using a hash algorithm. we cannot access a hashed table using its index.

Examples:

1.

DATA: BEGIN OF LINE,

COL1,

COL2,

END OF LINE.

DATA: ETAB LIKE TABLE OF LINE WITH HEADER LINE,

FTAB LIKE TABLE OF LINE.

LINE-COL1 = 'A'. LINE-COL2 = 'B'.

APPEND LINE TO ETAB.

MOVE ETAB[] TO FTAB.

LOOP AT FTAB INTO LINE.

WRITE: / LINE-COL1, LINE-COL2.

ENDLOOP.

The output is:

A B

The example creates two standard tables ETAB and FTAB with the line type of the

structure LINE. ETAB has a header line. After filling ETAB line by line using the

APPEND statement, its entire contents are assigned to FTAB. Note the brackets in the statement.

2.

DATA: FTAB TYPE SORTED TABLE OF F

WITH NON-UNIQUE KEY TABLE LINE,

ITAB TYPE HASHED TABLE OF I

WITH UNIQUE KEY TABLE LINE,

FL TYPE F.

DO 3 TIMES.

INSERT SY-INDEX INTO TABLE ITAB.

ENDDO.

FTAB = ITAB.

LOOP AT FTAB INTO FL.

WRITE: / FL.

ENDLOOP.

The output is:

1.000000000000000E+00

2.000000000000000E+00

3.000000000000000E+00

FTAB is a sorted table with line type F and a non-unique key. ITAB is a hashed table with line type I and a unique key. The line types, and therefore the entire tables, are convertible. It is therefore possible to assign the contents of ITAB to FTAB. When you assign the unsorted table ITAB to the sorted table FTAB, the contents are automatically sorted by the key of FTAB.

3.

DATA: BEGIN OF ILINE,

NUM TYPE I,

END OF ILINE,

BEGIN OF FLINE,

NUM TYPE F,

END OF FLINE,

ITAB LIKE TABLE OF ILINE,

FTAB LIKE TABLE OF FLINE.

DO 3 TIMES.

ILINE-NUM = SY-INDEX.

APPEND ILINE-NUM TO ITAB.

ENDDO.

FTAB = ITAB.

LOOP AT FTAB INTO FLINE.

WRITE: / FLINE-NUM.

ENDLOOP.

The output might look like this:

6.03823403895813E-154

6.03969074613219E-154

6.04114745330626E-154

Here, the line types of the internal tables ITAB and FTAB are structures each with

one component of type I or F. The line types are convertible, but not compatible.

Therefore, when assigning ITAB to FTAB, the contents of Table ITAB are converted

to type C fields and then written to FTAB. The system interprets the transferred data as type F fields, and obtains meaningless results.

4.

TYPES: BEGIN OF LINE,

COLUMN1 TYPE I,

COLUMN2 TYPE I,

COLUMN3 TYPE I,

END OF LINE.

TYPES ITAB TYPE SORTED TABLE OF LINE WITH UNIQUE KEY COLUMN1.

The program defines a table type ITAB. It is a sorted table, with line type of the

structure LINE and a unique key of the component COLUMN1.

5.

TYPES VECTOR TYPE HASHED TABLE OF I WITH UNIQUE KEY TABLE

LINE.

TYPES: BEGIN OF LINE,

COLUMN1 TYPE I,

COLUMN2 TYPE I,

COLUMN3 TYPE I,

END OF LINE.

TYPES ITAB TYPE SORTED TABLE OF LINE WITH UNIQUE KEY COLUMN1.

TYPES: BEGIN OF DEEPLINE,

FIELD TYPE C,

TABLE1 TYPE VECTOR,

TABLE2 TYPE ITAB,

END OF DEEPLINE.

TYPES DEEPTABLE TYPE STANDARD TABLE OF DEEPLINE

WITH DEFAULT KEY.

The program defines a table type VECTOR with type hashed table, the elementary

line type I and a unique key of the entire table line. The second table type is the

same as in the previous example. The structure DEEPLINE contains the internal

table as a component. The table type DEEPTABLE has the line type DEEPLINE.

Therefore, the elements of this internal table are themselves internal tables. The key is the default key - in this case the column FIELD. The key is non-unique, since the table is a standard table.

Regards,

Shakir

Former Member
0 Kudos

Standard tables

This is the most appropriate type if you are going to address the individual table entries using the index. Index access is the quickest possible access. You should fill a standard table by appending lines (ABAP APPEND statement), and read, modify and delete entries by specifying the index (INDEX option with the relevant ABAP command). The access time for a standard table increases in a linear relationship with the number of table entries. If you need key access, standard tables are particularly useful if you can fill and process the table in separate steps. For example, you could fill the table by appending entries, and then sort it. If you use the binary search option with key access, the response time is logarithmically proportional to the number of table entries.

Sorted tables

This is the most appropriate type if you need a table which is sorted as you fill it. You fill sorted tables using the INSERT statement. Entries are inserted according to the sort sequence defined through the table key. Any illegal entries are recognized as soon as you try to add them to the table. The response time for key access is logarithmically proportional to the number of table entries, since the system always uses a binary search. Sorted tables are particularly useful for partially sequential processing in a LOOP if you specify the beginning of the table key in the WHERE condition.

Hashed tables

This is the most appropriate type for any table where the main operation is key access. You cannot access a hashed table using its index. The response time for key access remains constant, regardless of the number of table entries. Like database tables, hashed tables always have a unique key. Hashed tables are useful if you want to construct and use an internal table which resembles a database table or for processing large amounts of data.

reward if useful

Former Member
0 Kudos

we have two major types of internal tables.

1) <b>index based</b>

2) <b>non-index based</b>.

again index based table can be sub divided into

1) stabndard table

2) sorted table.

some properties of standard tables are

non-unique, linear search

some properties of sorted tables are

unique/non-unique, binary search

non-index table is hashed table

some properties of hasehed tables are

unique, hashed algorithm

in abap report you can define as follows

<u>example.</u>

data : itab type standard table of XXXXX with non-unique default key initial size 10 with header line.

Former Member
0 Kudos

Hi

<b>Standard Internal Tables</b>

Standard tables have a linear index. You can access them using either the index or the key. If you use the key, the response time is in linear relationship to the number of table entries. The key of a standard table is always non-unique, and you may not include any specification for the uniqueness in the table definition.

This table type is particularly appropriate if you want to address individual table entries using the index. This is the quickest way to access table entries. To fill a standard table, append lines using the (APPEND) statement. You should read, modify and delete lines by referring to the index (INDEX option with the relevant ABAP command). The response time for accessing a standard table is in linear relation to the number of table entries. If you need to use key access, standard tables are appropriate if you can fill and process the table in separate steps. For example, you can fill a standard table by appending records and then sort it. If you then use key access with the binary search option (BINARY), the response time is in logarithmic relation to

the number of table entries.

<b>Sorted Internal Tables</b>

Sorted tables are always saved correctly sorted by key. They also have a linear key, and, like standard tables, you can access them using either the table index or the key. When you use the key, the response time is in logarithmic relationship to the number of table entries, since the system uses a binary search. The key of a sorted table can be either unique, or non-unique, and you must specify either UNIQUE or NON-UNIQUE in the table definition. Standard tables and sorted tables both belong to the generic group index tables.

This table type is particularly suitable if you want the table to be sorted while you are still adding entries to it. You fill the table using the (INSERT) statement, according to the sort sequence defined in the table key. Table entries that do not fit are recognised before they are inserted. The response time for access using the key is in logarithmic relation to the number of

table entries, since the system automatically uses a binary search. Sorted tables are appropriate for partially sequential processing in a LOOP, as long as the WHERE condition contains the beginning of the table key.

<b>Hashed Internal Tables</b>

Hashes tables have no internal linear index. You can only access hashed tables by specifying the key. The response time is constant, regardless of the number of table entries, since the search uses a hash algorithm. The key of a hashed table must be unique, and you must specify UNIQUE in the table definition.

This table type is particularly suitable if you want mainly to use key access for table entries. You cannot access hashed tables using the index. When you use key access, the response time remains constant, regardless of the number of table entries. As with database tables, the key of a hashed table is always unique. Hashed tables are therefore a useful way of constructing and

using internal tables that are similar to database tables.

<b>Index Tables</b>

Index table is only used to specify the type of generic parameters in a FORM or FUNCTION. That means that you can't create a table of type INDEX.

Internal tables are not DB tables. Standard and Sorted tables in combined are basically called as Index tables and there nothing else. Here is the hierarchy

ANY TABLE

|

-


| |

Index Tables Hashed Table

|

-


| |

Standard Table Sorted Table

http://www.geekinterview.com/question_details/1498

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

<b>Reward if usefull</b>