SAP ABAP - Sorted Internal Table (Index Table) With Example.


Submitted By: Shilpa Gunjan (L&T Infotech)

- Sorted tables are always sorted by key i.e. records are always in sorted order. Hence sorted tables cannot be sorted again. If you still try to sort a sorted internal table you will get an error message '<Internal Table Name>' is a table of the kind SORTED. You cannot use the SORT command with this type of table.’


- Sorted tables are also referred as Index tables because the entries can be accessed via index.


- Sorted tables can be accessed either by index or by key. For a key access the response time depends logarithmically on the number of tables entries because read access is carried out via binary search.


- Reading entries from sorted table is efficient because the access is via binary search.


- The key that is used to read sorted table are always either unique or non-unique. Sorted Internal tables cannot be declared without UNIQUE/NON-UNIQUE Keyword.


- Sorted tables are mostly used when there is a need of a table which gets sorted as entries are appended to it. A new entry added to the sorted table gets sorted as per the table key.


- Sorted tables are particularly suited for partially sequential processing (LOOP ….WHERE). For example, when a small part of a table is to be processed via key accesses for which only the initial part of the key is given. Key accesses to the table key can also be carried out effectively by the sorted tables.


SYNTAX:

DATA: <Internal table name> TYPE SORTED TABLE OF <structure/type> WITH UNIQUE / NON-UNIQUE <key>.


EXAMPLES:


TYPES: BEGIN OF x_mara,
matnr LIKE mara-matnr,
mtart LIKE mara-mtart,
matkl LIKE mara-matkl,
flag TYPE c,
END OF x_mara.


DATA: it_mara TYPE SORTED TABLE OF x_mara WITH NON-UNIQUE KEY mtart.

DATA: it_mara1 TYPE SORTED TABLE OF x_mara WITH UNIQUE KEY matnr.


SAMPLE PROGRAM ON SORTED INTERNAL TABLE:

1) USING KEY ACCESS.

2) USING INDEX ACCESS.



RELATED POSTS:

- INTERNAL TABLES - Introduction, Advantages & Types Of Internal Tables.

- STANDARD INTERNAL TABLE (Index Table) - Introduction With Sample Programs.

- SORTED INTERNAL TABLE (Index Table) - Introduction, Advantages & Performance.

- SORTED INTERNAL TABLE With Key Access (Performance) - Sample Program.

- SORTED INTERNAL TABLE With INDEX Access (Performance) - Sample Program.

- HASHED INTERNAL TABLE (Non-Index Table) - Introduction, Advantages & Performance.

- HASHED INTERNAL TABLE - Partial Key Access (Performance) - Sample Program.

- HASHED INTERNAL TABLE - Table's Key Access (Performance) - Sample Program.


Your suggestions and comments are welcome in this section.

Please mail all your contributions to administrator@abapmadeeasy.com We request you to mention your Name, Designation, Experience & Organization you are working for. Your posts will be verified and posted in this site with your name.

No comments:

Post a Comment