Monday, December 22, 2008

Internal Tables

Internal Tables

-> Tables are the most important data structures in R/3 system.
-> Data with long life are stored in RDBMS.
-> Apart from database tables you can create internal tables that exist only at runtime of the program.
-> ABAP/4 offers several operations for working with internal tables.
-> For e.g. it allows to search for lines or append, insert or delete lines.
-> The no. of lines of an internal table is not fixed. If required, the system expands internal tables at runtime.
-> That means if you want to read a database table into an internal table, you must not know its size in advance. -> This makes it easier to use.

Use of Internal Tables

-> Perform Table calculations
-> Re-organize table contents
-> Create a list

Working with Internal Tables
-> Declare an Internal Table
-> Fill an Internal Table
-> Change/output/delete individual elements
-> Sort tables by any field
-> Understand and use control levels

Declare an Internal Table
Before you can use them you need to declare the structure of an IT.
Eg: DATA:BEGIN of itab occurs 10,
Carrid like spfli-carrid,
Connid like spfli-connid,
END of itab.


Or define a structure
Eg: TYPES:BEGIN of structure,
Carrid like spfli-carrid,
Connid like spfli-connid,
END of structure.
DATA: itab TYPE structure occurs 10.

OCCURS defines an internal table and no defines no of lines the table has after initialization.However, the size is variable ie size can change as per requirements

Work Area
To change or output the contents of an IT, you need a work area.

Types of Internal Tables

The various table types have the following hierarchy:
STANDARD TABLE
->Defines the table as a 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.
-> For the sake of compatibility, you can use TABLE as a synonym of STANDARD TABLE

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.
-> You can also access sorted tables by index operations.
-> When you insert using an index, the system checks to ensure that the sort sequence has been correctly maintained.
For this reason, it takes longer than inserting entries in a standard table. -> As a rule, you should only access sorted tables using their key.

HASHED TABLE
-> Defines the table as one that is managed with an internal hash procedure.
-> You can imagine a hashed table as a set, whose elements you can address using their unique key. Unlike standard and sorted tables, you cannot access hash tables using an index.
-> All entries in the table must have a unique key. Access time using the key is constant, regardless of the number of table entries.
-> 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.

INDEX TABLE
-> Standard and sorted tables belong to the generic class index tables.
-> An index table is one that you can access using an index. You can currently only use the table type INDEX TABLE to specify the type of generic parameters in a FORM or a FUNCTION.
-> Hashed tables are not index tables, and cannot therefore be passed to parameters defined as INDEX TABLE.

1 comment:

magnific said...

This is such a great resource that you are providing and you give it away for free. I love seeing websites that understand the value of providing a quality resource for free. It?s the old what goes around comes around routine. Did you acquired lots of links and I see lots of trackbacks??
http://www.saphanatraining.in/

Post a Comment