SAP ABAP - Standard Internal Table (Index Table) With Example


Submitted By: Shilpa Gunjan (L&T Infotech)

- Standard tables have linear index.


- Standard table is accessed either via an index or a key. And always remember the key of a standard table is always non-unique. If no key is specified, the standard table takes a default key which is a combination of all the character like fields.


- Records can be accessed through both Index and Conditions.

READ TABLE it_itab INTO wa_itab INDEX ind_no.

OR

READ TABLE it_itab INTO wa_itab WITH KEY condition.

Here the it_itab can be sorted. Accessing and searching time for the record depends on the number of records because searching is either linear or binary (when we explicitly use BINARY SEARCH keyword in READ statement).


- If a standard table is accessed using a key, then the response time is in linear relationship to the number of table entries. For example, if there are 10 rows in a table and I want to process the 7th row, then the search is row by row in this case. Hence such tables are not suitable to access if there is a large amount of data.


- Standard tables are used when the table has to be filled quickly because the system does not have to check whether there are already existing entries.


- Standard tables can contain duplicate entries as it has a non–unique key.


- Standard tables should only be used for small tables or tables that can be processed using the index accesses. For larger standard tables, binary search should be used for reading data from it.


SYNTAX:

DATA: it_itab type standard table of x_itab.

OR

DATA:it_itab type standard table of x_itab.



Example:

REPORT z_internal_table_test.

*Sorted Internal table (Performance)

TYPES: BEGIN OF x_marc,
matnr LIKE marc-matnr,
werks LIKE marc-werks,
PSTAT LIKE marc-PSTAT,
flag TYPE c,
END OF x_marc.

*Internal Table Declaration
DATA: it_marc TYPE STANDARD TABLE OF x_marc.

* Table Workarea Declaration
DATA: wa_marc TYPE x_marc.

* Variable Declaration
DATA: v_counter TYPE i,
v_runtime1 TYPE i,
v_runtime2 TYPE i,
v_tabix LIKE sy-tabix.

SELECT matnr    " Material Number
werks                  " Plant
PSTAT               " Maintenance status
FROM marc
INTO TABLE it_marc.


GET RUN TIME FIELD v_runtime1.
LOOP AT it_marc INTO wa_marc WHERE werks EQ '1501'.
ADD 1 TO v_counter.
ENDLOOP.

GET RUN TIME FIELD v_runtime2.

* Calculate Runtime
v_runtime2 = v_runtime2 - v_runtime1.

WRITE: 'Total No. Of Records Processed Is:'.
WRITE: v_counter.
WRITE:/ 'Total Time Taken To Process Data Is (In ms):'.
WRITE: v_runtime2.


OUTPUT:

Total No. Of Records Processed Is: 8,881
Total Time Taken To Process Data Is (In ms): 3,676


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