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: 

differnt types of internal table

Former Member
0 Kudos
724

hi all,

Different types of internal table are \

1. standard

2. sorted and

3. hashed table.

can anyone explain me with examples of the above mentioned internal tables.

regds

hari

7 REPLIES 7

Former Member
0 Kudos
143

Hi,

There are 3 types of Internal tables.

Standard Internal Tables:

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.

Sorted Internal Tables:

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.

Hashed Internal Tables:

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>Reward points</b>

Regards

Former Member
0 Kudos
143

Hi,

see below link:

http://www.sapmaterial.com/internal_tables_all.html

REWARD POINTS IF HHELPFUL.

Regards.

Srikanta Gope

Former Member

Former Member
0 Kudos
143

Hi,

Refer this:

Defining and reading internal tables

1. Types of internal tables

2. Defining an internal table

3. Reading internal tables

1. Types of internal tables

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

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

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

1.4 INDEX table

A table that can be accessed using an index.

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.

Standard tables and sorted tables are index tables.

1.5 ANY table

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

Standard, sorted and hashed tables belongs to ANY tables.

2. Defining an internal table

DATA itab TYPE table type of line type [WITH UNIQUE/NON-UNIQUE KEY <key>] [Iinitial size n] [WITH HEADER LINE]

Note: There are also other ways to define an internal table. Please refere to the documentation.

2.1 The KEY option

KEY key1,,keyn :

key1..keyn are fields in the table. The sequence in which you specify the key is significant.

DEFAULT KEY :

The key fields are the standard keys. Note that you can only specify an empty key for tables with access type STANDARD TABLE. The standard key basically comprises all tables fields with character-like types (type ( C, STRING, D, T, N, X, XSTRING). In particular, components with a numeric type (also refer to ABAP numeric types) and table components usually do not belong to the standard key.

Example:

types:

begin of t_makt,

matnr like makt-matnr,

maktx like makt-maktx,

end of t_makt.

data:

  • Define the table

gi_makt type sorted table of t_makt with unique key matnr.

  • Define the work area for the table if necessary

gi_makt type t_makt.

3. Reading internal tables

READ TABLE itab WITH TABLE KEY k1 = v1 k2 = v2 [additions]

Note: In case of more than one match, it is the first match that is selected.

STANDARD TABLE: The system searches from the start of the table. The response time is in linear relation to the number of table entries.

SORTED TABLE: The response time is in logarithmic relation to the number of table entries.

HASHED TABLE: The response time is constant

READ TABLE itab WITH KEY k1 = v1 k2 = v2 [BINARY SEARCH] [additions]

Note: In case of more than one match, it is the first match that is selected.

STANDARD TABLE: If you use the ... BINARY SEARCH addition, the system uses a binary search. Otherwise, the search is sequential. This assumes that the internal table is sorted in ascending order in the sequence of the specified key fields.

SORTED TABLE: If the specified key fields form a left-justified extract of the table key, the search is binary, otherwise sequential.

HASHED TABLE: Sequential search.

READ TABLE itab INDEX i [additions]

Accessing the table entry with the index i.

Additions:

INTO wa - wa is used as output area

ASSIGNING <fs> - The field symbol <fs> is assigned to the entry. This saves the cost of copying the contents in comparison to the first addition. However, this addition does involve table administration costs, and it is therefore only worthwile for lines longer than around 300 bytes.

COMPARING f1...fn - If the system find an entry, the system compares the subfields f1, f2, ... with the corresponding fields of the work area before they are transported into it.

COMPARING ALL FIELDS

TRANSPORTING f1 f2 - If the system finds an entry, it does not transfer all of the subfields (default) into the work area, but only the specified fields f1 f2 ...; the other subfields remain unchanged.

TRANSPORTING NO FIELDS

Example:

loop at gi_mseg into g_mseg.

read table gi_makt

with table key matnr = g_mseg-matnr

into g_makt.

endloop.

Jogdand M B

Former Member
0 Kudos
143

hi,

Here is the link that has the details regardign the internal table and its types.internal table types

<b>Standard tables</b>

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.

<b>Sorted tables</b>

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.

<b>Hashed tables</b>

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.

<b>rewards if helpful.</b>

swati

Former Member
0 Kudos
143

hi,

data: begin of struct,

v_id type i,

v_name(10) type c,

v_phn type i,

end of struct.

&----


"STANDARD TABLE.

&----


data itab like standard table of struct with default key .

write 'standard table'.

struct-v_id = 1.

struct-v_name = 'subash'.

struct-v_phn = 234567.

"INSERT struct into ITAB.

append struct to itab.

struct-v_id = 3.

struct-v_name = 'sanchana'.

struct-v_phn = 2378499.

INSERT struct into ITAB index 1.

"append struct to itab.

struct-v_id = 2.

struct-v_name = 'sanchith'.

struct-v_phn = 2455667.

INSERT struct into ITAB index 2 .

loop at itab into struct.

write: / struct-v_id , struct-v_name,struct-v_phn.

endloop.

skip.

uline.

&----


"sorted table.

&----


data itab1 like sorted table of struct with non-unique key v_id.

write 'sorted table'.

struct-v_id = 3.

struct-v_name = 'subash'.

struct-v_phn = 234567.

INSERT struct into TABLE ITAB1.

"append struct to itab.

struct-v_id = 2.

struct-v_name = 'sanchana'.

struct-v_phn = 2378499.

INSERT struct into table ITAB1.

"append struct to itab.

struct-v_id = 1.

struct-v_name = 'sanchith'.

struct-v_phn = 2455667.

INSERT struct into ITAB1 index 1.

"append struct to itab.

loop at itab1 into struct.

write: / struct-v_id , struct-v_name, struct-v_phn.

endloop.

skip.

uline.

&----


"hashed table

&----


data itab2 like hashed table of struct with unique key v_id.

write 'hashed table'.

struct-v_id = 1.

struct-v_name = 'subash'.

struct-v_phn = 234567.

INSERT struct into TABLE ITAB2.

struct-v_id = 3.

struct-v_name = 'sanchana'.

struct-v_phn = 2378499.

INSERT struct into TABLE ITAB2.

struct-v_id = 2.

struct-v_name = 'sanchith'.

struct-v_phn = 2455667.

INSERT struct into TABLE ITAB2.

&--


SORTED USING SORT STATEMENT--

loop at itab2 into struct.

write:'non-sorted table' , / struct-v_id , struct-v_name, struct-v_phn.

endloop.

sort itab2 by v_id.

SKIP.

loop at itab2 into struct.

write: 'sorted hash table', / struct-v_id , struct-v_name, struct-v_phn.

endloop.

SKIP.

ULINE.

Regards,

Rusidar S.

Former Member
0 Kudos
143

hi all,,

thanxs a lot for the quick response. i have assigned points for everyone

regds

hari