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 types

Former Member
0 Likes
1,512

hi all,

whn we are going to use standard , sorted and harshed table...

wht are the examples for the same..

regards

suprith

1 ACCEPTED SOLUTION
Read only

Former Member
13 REPLIES 13
Read only

Former Member
Read only

Former Member
0 Likes
1,363

hi

<b>STANDARD TABLE or TABLE</b>

For creating standard tables.

<b>SORTED TABLE</b>

For creating sorted tables.

<b>HASHED TABLE</b>

For creating hashed tables.

Fully-specified table types determine how the system will access the entries in the table in key operations. It uses a linear search for standard tables, a binary search for sorted tables, and a search using a hash algorithm for hashed tables.

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.

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.

<b>

reward points for useful ans</b>

regards

Aarti

Read only

Former Member
0 Likes
1,363

all normal cases we go for standard

when we are about to use collect we go for sorted or indexed

Read only

Former Member
0 Likes
1,363

Hi,

See below link :

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

Reward points if helpful.

Regards.

Srikanta Gope

Read only

Former Member
0 Likes
1,363

Hi,

From the following link you can download Abap Programing Complete Guide. And in that document go to page no. 251. You can get full details with examples of Internal tables. The link is:

http://www.sapbrainsonline.com/TUTORIALS/TECHNICAL/ABAP_tutorial.html

Regards,

Bhaskar

Read only

Former Member
0 Likes
1,363

Hi,

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

Regards,

ravish

<b>plz dont forget to reward points if useful</b>

Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
1,363

Hi,

<b>Standard table</b>

We recommend using standard tables if you plan to access your data through

an index – that is, when the sequence of the records is important and when

sorting and uniqueness are not essential. Sorting and binary search are

also available when using a standard table, but you have to program these

functions by hand.

Managing rankings is a typical example application.

Moreover, you will often have to use this table type in order to ensure

compatibility.

<b>Sorted table</b>

When you choose to use a sorted table, it will normally be because you want

to define a unique key. If you decide you need to sort the table or access

it using a binary search, you can always program these functions by hand,

like with standard tables. While hashed tables also provide unique keys, new

records are always added to sorted tables in the appropriate sort sequence.

Moreover, the initial dataset is set up more quickly.

Overall, if a table contains relatively few entries but has to deal with many

changing accesses, a sorted table can deliver better performance than a

hashed table.

A typical area of use here is the preparation and execution of mass database

changes. The most efficient way of doing this is to create a local copy of the

dataset in the program, make the changes to the copy, and then write all of its

data back to the database table. When you are dealing with large amounts of

data, this method both saves runtime and reduces the load on the database

server. Since the internal table represents a database table in this case, you

should use a unique key to ensure the records are unique as well. Automatic

sorting can also bring further advantages.

<b>Hashed table</b>

The hash algorithm calculates the address of an entry directly, based on

the key. This means that, with larger tables, the access time is reduced

significantly compared to a binary search.

In a loop, however, a hashed table always has to be searched completely

(table scan). Because the records are usually distributed without any sorting,

a sorted table might deliver better performance after all if you loop over the

first part of the key, or it could even make sense to sort the hashed table.

Therefore, using this table type only makes sense when you have to store

large amounts of data locally for mostly read access. At the same time,

the key of the hashed table has to be designed to enable unique access with

the full key.

Accordingly, hashed tables are generally used for the following situations:

To buffer or compose large quantities of data from several different database

tables where Dictionary views or nested SELECT statements are not possible.

(Open SQL joins bypass the table buffer of the database interface anyway.)

Regards,

Sesh

Read only

Former Member
0 Likes
1,363

Hi,

Standard table means when you are refering existing or custom table/structure

internal table with header line.

data:itab like sflight occurs 0 with header line.

data:begin of itab occurs 0,

vbeln type vbap-vbeln,

posnr type vbap-posnr,

matnr type vbap-matnr,

end of itab.

types:begin of ty_tab,

vbeln type vbap-vbeln,

posnr type vbap-posnr,

matnr type vbap-matnr,

end of ty_tab.

Internal table with out headerline

data:itab type standard table of ty_tab.

data: x_tab type ty_tab. "work area

or

data:x_tab like line of itab.

sorted table --->when you want to maintain records in a sorted order

data:itab type sorted table of mara with unique key matnr.

hashed table-->itab type hashed table of mara with unique key matnr.

it is similar to database table here we cannt access index we can do only read and processing.

regards

suman

Read only

Former Member
0 Likes
1,363

hi,

Standard tables uses linear search while referring fields.

sorted tables uses binary search it mainly used to sort bulk fields in ascending or descending order.

Hashed tables uses hash algorithms while referring fields.

Read only

Former Member
0 Likes
1,363

whts the use of internal tables

Read only

0 Likes
1,363

Hi,

The useWe use internal tables for various reasons,

Mainly to get a local copy of the Data the we need from the Data base,

Then say update the data and push it back to database or

say Insert inew data and push it onto the database tables.

We can also internal tables to share data between Say Calling program and a Funcion module being called.

For displaying the data using ALV or TABLE CONTROL.

Regards,

Sesh

Read only

Former Member
0 Likes
1,363

hi suprith

internal tables are used for tempoprary storage. in report programing u can make changes directly to the database tables.

so internal tables act as an intermeediate .first the values/ data is stored in internal table and then database tables are modified through these internal tables.

example:

<b>modify <database> from itab.</b>

hope it clears ur doubt

regards

ravish

<b>plz dont forget to reward points if useful</b>

Read only

Former Member
0 Likes
1,363

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.

Index Tables

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