{"id":7635,"date":"2025-08-24T16:52:22","date_gmt":"2025-08-24T11:22:22","guid":{"rendered":"https:\/\/www.sapewmhelp.com\/?question=types-of-internal-tables-in-abap"},"modified":"2025-08-24T16:53:01","modified_gmt":"2025-08-24T11:23:01","slug":"types-of-internal-tables-in-abap","status":"publish","type":"question","link":"https:\/\/www.sapewmhelp.com\/?question=types-of-internal-tables-in-abap","title":{"rendered":"Types of Internal Tables in ABAP"},"content":{"rendered":"<p>SAP defines <strong>three main types<\/strong> of internal tables based on their structure and access method:<\/p>\n<h5>1. <strong>Standard Table (<code>STANDARD TABLE<\/code>)<\/strong><\/h5>\n<ul>\n<li>\n<p>Default type if nothing is specified.<\/p>\n<\/li>\n<li>\n<p>Entries are stored <strong>unsorted<\/strong> (in the order you append them).<\/p>\n<\/li>\n<li>\n<p><strong>Index-based access<\/strong> (like arrays).<\/p>\n<\/li>\n<li>\n<p><strong>Duplicate entries allowed<\/strong>.<\/p>\n<\/li>\n<li>\n<p><strong>Access time:<\/strong><\/p>\n<ul>\n<li>\n<p>By <strong>index<\/strong> \u2192 very fast (O(1))<\/p>\n<\/li>\n<li>\n<p>By <strong>key<\/strong> \u2192 linear search (O(n))<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>Use Case:<\/strong> Small-to-medium datasets where duplicates are needed, sequential processing.<\/p>\n<p>&nbsp;<\/p>\n<p>DATA: it_mara TYPE STANDARD TABLE OF mara WITH DEFAULT KEY,<br \/>wa_mara TYPE mara.<\/p>\n<p>SELECT * FROM mara INTO TABLE it_mara UP TO 10 ROWS.<br \/>READ TABLE it_mara INTO wa_mara INDEX 5. &#8221; Access by index<\/p>\n<p>&nbsp;<\/p>\n<h5>2. <strong>Sorted Table (<code>SORTED TABLE<\/code>)<\/strong><\/h5>\n<ul>\n<li>\n<p>Entries are always stored in a <strong>sorted order<\/strong> (by key).<\/p>\n<\/li>\n<li>\n<p>No need to <code>SORT<\/code> explicitly.<\/p>\n<\/li>\n<li>\n<p><strong>Unique or non-unique keys<\/strong> possible (depending on definition).<\/p>\n<\/li>\n<li>\n<p><strong>Binary search<\/strong> used internally for key access.<\/p>\n<\/li>\n<li>\n<p><strong>Access time:<\/strong><\/p>\n<ul>\n<li>\n<p>By <strong>key<\/strong> \u2192 fast (O(log n))<\/p>\n<\/li>\n<li>\n<p>By <strong>index<\/strong> \u2192 slower than standard<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>Use Case:<\/strong> When you frequently read data by key and want it sorted automatically.<\/p>\n<p>&nbsp;<\/p>\n<p>DATA: it_mara_sorted TYPE SORTED TABLE OF mara<br \/>WITH UNIQUE KEY matnr.<\/p>\n<p>SELECT * FROM mara INTO TABLE it_mara_sorted UP TO 10 ROWS.<br \/>READ TABLE it_mara_sorted WITH TABLE KEY matnr = &#8216;MAT001&#8217;<br \/>INTO DATA(wa_mara).<\/p>\n<p>&nbsp;<\/p>\n<h5>3. <strong>Hashed Table (<code>HASHED TABLE<\/code>)<\/strong><\/h5>\n<ul>\n<li>\n<p>Entries are stored in <strong>hash algorithm format<\/strong> (like a dictionary).<\/p>\n<\/li>\n<li>\n<p><strong>Only unique keys allowed<\/strong>.<\/p>\n<\/li>\n<li>\n<p><strong>No index access<\/strong> \u2192 can only be accessed via key.<\/p>\n<\/li>\n<li>\n<p><strong>Access time:<\/strong> By key \u2192 constant (O(1)) on average.<\/p>\n<\/li>\n<li>\n<p>Best for <strong>large datasets<\/strong> when you always access by key.<\/p>\n<\/li>\n<\/ul>\n<p><strong>Use Case:<\/strong> Fast key-based lookups, like material master lookup by MATNR.<\/p>\n<p>&nbsp;<\/p>\n<p>DATA: it_mara_hashed TYPE HASHED TABLE OF mara<br \/>WITH UNIQUE KEY matnr.<\/p>\n<p>SELECT * FROM mara INTO TABLE it_mara_hashed UP TO 1000 ROWS.<br \/>READ TABLE it_mara_hashed WITH TABLE KEY matnr = &#8216;MAT001&#8217;<br \/>INTO DATA(wa_mara).<\/p>\n<p>Summary :\u00a0<\/p>\n<table>\n<thead>\n<tr>\n<th>Type<\/th>\n<th>Sorted?<\/th>\n<th>Duplicates?<\/th>\n<th>Access by Index<\/th>\n<th>Access by Key<\/th>\n<th>Performance<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>Standard<\/strong><\/td>\n<td>No<\/td>\n<td>Yes<\/td>\n<td>Yes<\/td>\n<td>Linear Search<\/td>\n<td>Best for small, sequential<\/td>\n<\/tr>\n<tr>\n<td><strong>Sorted<\/strong><\/td>\n<td>Yes<\/td>\n<td>Optional<\/td>\n<td>Yes<\/td>\n<td>Binary Search<\/td>\n<td>Best for ordered + key access<\/td>\n<\/tr>\n<tr>\n<td><strong>Hashed<\/strong><\/td>\n<td>N\/A<\/td>\n<td>No<\/td>\n<td>No<\/td>\n<td>Hash Search<\/td>\n<td>Best for large, key-only access<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","question-category":[158],"question_tags":[178,372,189,177],"class_list":["post-7635","question","type-question","status-publish","hentry","question-category-abap","question_tags-abap","question_tags-internal-tables","question_tags-report","question_tags-sap"],"_links":{"self":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/question\/7635","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/question"}],"about":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/types\/question"}],"author":[{"embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7635"}],"wp:attachment":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7635"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fquestion-category&post=7635"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fquestion_tags&post=7635"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}