SlideShare a Scribd company logo
Lecture 12 Advanced Internal Tables BCO5647 Applications Programming Techniques (ABAP)
Readings & Objectives Readings Keller & Keller   Chapter 4 Section 4.7.1 & 4.7.3    Objectives This lecture will Revise the structure of internal tables Review the attributes of internal tables Describe the three internal table kinds: standard, sorted, hashed Examine the features and application of STANDARD internal tables Examine the features and application of SORTED internal tables Examine the features and application of HASHED internal tables Distinguish between the use of work areas Vs header lines when processing internal tables
Internal Tables as Dynamic Data Objects Internal tables are data objects that allow you to store datasets with a fixed structure in memory. The data is stored row by row in memory. Each row has the same structure. You can also refer to each component in a row as a column in the internal table. You refer to each row in the internal table as a table row or table entry. Internal tables are dynamic data objects that can hold any number of rows of a fixed type. The number of rows in an internal table is limited only by the capacity of the specific system with which you are working.
Attributes of an Internal Table The data type of an internal table is fully specified by its: Row type The row type defines the attributes of the individual columns. You normally enter a structure type, but any data type is possible. Key definition The key columns and their sequence determine the criteria by which the system identifies table rows. You can define the key as either UNIQUE or NON-UNIQUE. The uniqueness of the key must be compatible with the access type you have chosen for the table. If the key is unique, there can be no duplicate entries in the table. Access type Key access – like database tables – works via field contents. Index access, unlike for database tables, the system assigns row numbers to certain kinds of internal tables. This means that you can sometimes use the index to access rows in the table.
Internal Table Kinds Internal Tables can be divided into three table kinds, depending on the possible access type required: Standard Tables  – the row number is maintained internally. Both index and key access are possible. Sorted Tables  – Data records are sorted by the key and stored in these tables. Their index is also maintained internally. Both index and key access are possible. Hashed Tables  – The runtime-optimized data records are maintained here. This requires a unique key. Hashed tables only allow for key access.
Defining Internal Tables - Standard Example 1 : Example 2 : DATA:  itab TYPE STANDARD TABLE OF scarr   WITH UNIQUE KEY carrid. Example 3 : DATA:  itab TYPE TABLE OF scarr.
Defining Internal Tables: Sorted & Hashed
Work Area or Header Line You can define internal tables either with (addition WITH HEADER LINE) or without header lines. An internal table with a header line consists of a work area (header line) and the actual table body. You address both objects using the  same name . Reading an Internal Table using LOOP. LOOP at itab INTO wa. LOOP at itab.   WRITE wa-carrid.     WRITE itab-carrid. ENDLOOP. ENDLOOP.
Hashed Internal Table Access to a hashed table is implemented using a hash algorithm. This means that the data records are distributed randomly but evenly over a particular memory area. Their addresses are stored in a separate table,  the hash table . The hash function uses the key data to calculate the address where the hashed table entry is located. If a  single record  is accessed using a  fully  specified key, the hash function can use the key immediately to determine the address of the hashed table entry. That is where the address of the actual data record is stored. Using a hash technique means that the access time no longer depends on the total number of entries in the table. The access time is therefore very short.  Hashed tables are therefore particularly useful for large tables with which you predominantly use read access.
Internal Table – single-record access Whenever you want to read individual table rows by declaring a complete key, use READ TABLE ... WITH  TABLE  KEY. This achieves the fastest single-record access with a key.  If the table is a standard table the SAP system performs a sequential search. If the table is a sorted table the SAP system performs a binary search. If the table is a hashed table the SAP system applies the hashed algorithm.
Internal Table Kinds - Summary Standard table Standard tables are best when you access data using an index, that is, the  order  of the data records is important but the sorting and the uniqueness are not crucial. If you decide you need to sort the table or access it using the key or a binary search, you can always program these functions by hand. Sorted table 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 use a binary search, you can always program these functions by hand. A sorted table also defines a unique key, but unlike a standard table, the data is sorted and then inserted. Also, the initial data is built up faster. Thus, if you have a table with few entries but lots of accesses that  change  the contents, a sorted table may be more efficient than a standard  table in terms of runtime. A typical use is the preparation and execution of  database changes by mass processing . The most efficient way of doing this is to create a local copy of the data in the program, make the changes to the copy, and then write all of its data records 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. Consequently, when you access the internal table, you should already use the unique key to ensure that the data record is unique. Automatic sorting can also bring further advantages.
Internal Table Kinds - Summary Hashed table The hash algorithm calculates the address of an entry based on the key. This means that, with larger tables, the access time is reduced significantly in comparison with a binary search. But when you use a loop with a hashed table, the whole table has to be scanned. Because the data records are usually totally unsorted, a sorted table may be more useful if you have a loop over the beginning of a key. Alternatively, you could also sort the hashed table.  Hashed table is only beneficial if you want to keep  large amounts of data  locally in the program and you mostly access it  only to read  it. You must ensure that you design your hashed table so that it is possible to specify the full key when you access it from your program. Typical use for hashed tables is for buffering or bundling large amounts of data from several database tables when an  ABAP Dictionary  view or a nested SELECT statement is not possible.

More Related Content

PPTX
Database indexing techniques
PPTX
Indexing
PPTX
SQL_Part1
PPTX
Key,ID Field and Tables Relationship
PPT
Database indexing framework
PDF
Ijebea14 228
PPTX
DOCX
Index in sql server
Database indexing techniques
Indexing
SQL_Part1
Key,ID Field and Tables Relationship
Database indexing framework
Ijebea14 228
Index in sql server

What's hot (20)

PPTX
Abap dictionary 1
PDF
Hash pre
PPSX
Index Tuning
PPT
Lecture03 abap on line
PPTX
oracle tables
PDF
Database Indexes
PPTX
Data storage and indexing
PPT
File organization 1
PPTX
Indexing structure for files
PPTX
Sql server ___________session_17(indexes)
PPT
Ardbms
DOCX
SAS Programming Notes
PPTX
Introduction of sql server indexing
PPTX
Advance Sqlite3
PPTX
B tree
PPTX
Database - R.D.Sivakumar
PPT
Ppt Lesson 13
PDF
Optimized cluster index generation
PPTX
Database tables
ODP
Database index by Reema Gajjar
Abap dictionary 1
Hash pre
Index Tuning
Lecture03 abap on line
oracle tables
Database Indexes
Data storage and indexing
File organization 1
Indexing structure for files
Sql server ___________session_17(indexes)
Ardbms
SAS Programming Notes
Introduction of sql server indexing
Advance Sqlite3
B tree
Database - R.D.Sivakumar
Ppt Lesson 13
Optimized cluster index generation
Database tables
Database index by Reema Gajjar
Ad

Similar to Lecture12 abap on line (20)

PDF
Indexing techniques
PPTX
DMBS Indexes.pptx
PDF
Database management system session 6
PPTX
File Organization in database management.pptx
DOCX
Internal tables
PPTX
dotnetMALAGA - Sql query tuning guidelines
PPTX
Getting to know oracle database objects iot, mviews, clusters and more…
PPTX
Sql performance tuning
PPTX
lecture 2 notes indexing in application of database systems.pptx
PDF
Sap abap material
PPTX
asdfew.pptx
PPT
Unit08 dbms
PPTX
Advance sqlite3
PPT
Sql Server Basics
PPTX
Overview of Storage and Indexing ...
PDF
8 i index_tables
PPT
1650607.ppt
PPTX
Index organized-table
PDF
Introduction to database
PPTX
Hashing and Hashtable, application of hashing, advantages of hashing, disadva...
Indexing techniques
DMBS Indexes.pptx
Database management system session 6
File Organization in database management.pptx
Internal tables
dotnetMALAGA - Sql query tuning guidelines
Getting to know oracle database objects iot, mviews, clusters and more…
Sql performance tuning
lecture 2 notes indexing in application of database systems.pptx
Sap abap material
asdfew.pptx
Unit08 dbms
Advance sqlite3
Sql Server Basics
Overview of Storage and Indexing ...
8 i index_tables
1650607.ppt
Index organized-table
Introduction to database
Hashing and Hashtable, application of hashing, advantages of hashing, disadva...
Ad

More from Milind Patil (20)

PDF
Abap slide class4 unicode-plusfiles
PDF
Step by step abap_input help or lov
PDF
Step bystep abap_fieldhelpordocumentation
PDF
Step bystep abap_field help or documentation
PDF
Abap slides user defined data types and data
PDF
Abap slides set1
PPT
Abap slide class3
PDF
Abap slide lock Enqueue data clusters auth checks
PDF
Step bystep abap_changinga_singlerecord
PDF
Abap slide lockenqueuedataclustersauthchecks
PDF
Abap slide exceptionshandling
PDF
Step bystep abap_changinga_singlerecord
PDF
Abap reports
PPT
Lecture16 abap on line
PPT
Lecture14 abap on line
PPT
Lecture13 abap on line
PPT
Lecture11 abap on line
PPT
Lecture10 abap on line
PPT
Lecture09 abap on line
PPT
Lecture08 abap on line
Abap slide class4 unicode-plusfiles
Step by step abap_input help or lov
Step bystep abap_fieldhelpordocumentation
Step bystep abap_field help or documentation
Abap slides user defined data types and data
Abap slides set1
Abap slide class3
Abap slide lock Enqueue data clusters auth checks
Step bystep abap_changinga_singlerecord
Abap slide lockenqueuedataclustersauthchecks
Abap slide exceptionshandling
Step bystep abap_changinga_singlerecord
Abap reports
Lecture16 abap on line
Lecture14 abap on line
Lecture13 abap on line
Lecture11 abap on line
Lecture10 abap on line
Lecture09 abap on line
Lecture08 abap on line

Recently uploaded (20)

PDF
Encapsulation theory and applications.pdf
PDF
cuic standard and advanced reporting.pdf
PPTX
Spectroscopy.pptx food analysis technology
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
Big Data Technologies - Introduction.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
Cloud computing and distributed systems.
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
NewMind AI Weekly Chronicles - August'25 Week I
Encapsulation theory and applications.pdf
cuic standard and advanced reporting.pdf
Spectroscopy.pptx food analysis technology
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
The AUB Centre for AI in Media Proposal.docx
Understanding_Digital_Forensics_Presentation.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
20250228 LYD VKU AI Blended-Learning.pptx
MYSQL Presentation for SQL database connectivity
Reach Out and Touch Someone: Haptics and Empathic Computing
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Big Data Technologies - Introduction.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Review of recent advances in non-invasive hemoglobin estimation
sap open course for s4hana steps from ECC to s4
Cloud computing and distributed systems.
Encapsulation_ Review paper, used for researhc scholars
NewMind AI Weekly Chronicles - August'25 Week I

Lecture12 abap on line

  • 1. Lecture 12 Advanced Internal Tables BCO5647 Applications Programming Techniques (ABAP)
  • 2. Readings & Objectives Readings Keller & Keller Chapter 4 Section 4.7.1 & 4.7.3 Objectives This lecture will Revise the structure of internal tables Review the attributes of internal tables Describe the three internal table kinds: standard, sorted, hashed Examine the features and application of STANDARD internal tables Examine the features and application of SORTED internal tables Examine the features and application of HASHED internal tables Distinguish between the use of work areas Vs header lines when processing internal tables
  • 3. Internal Tables as Dynamic Data Objects Internal tables are data objects that allow you to store datasets with a fixed structure in memory. The data is stored row by row in memory. Each row has the same structure. You can also refer to each component in a row as a column in the internal table. You refer to each row in the internal table as a table row or table entry. Internal tables are dynamic data objects that can hold any number of rows of a fixed type. The number of rows in an internal table is limited only by the capacity of the specific system with which you are working.
  • 4. Attributes of an Internal Table The data type of an internal table is fully specified by its: Row type The row type defines the attributes of the individual columns. You normally enter a structure type, but any data type is possible. Key definition The key columns and their sequence determine the criteria by which the system identifies table rows. You can define the key as either UNIQUE or NON-UNIQUE. The uniqueness of the key must be compatible with the access type you have chosen for the table. If the key is unique, there can be no duplicate entries in the table. Access type Key access – like database tables – works via field contents. Index access, unlike for database tables, the system assigns row numbers to certain kinds of internal tables. This means that you can sometimes use the index to access rows in the table.
  • 5. Internal Table Kinds Internal Tables can be divided into three table kinds, depending on the possible access type required: Standard Tables – the row number is maintained internally. Both index and key access are possible. Sorted Tables – Data records are sorted by the key and stored in these tables. Their index is also maintained internally. Both index and key access are possible. Hashed Tables – The runtime-optimized data records are maintained here. This requires a unique key. Hashed tables only allow for key access.
  • 6. Defining Internal Tables - Standard Example 1 : Example 2 : DATA: itab TYPE STANDARD TABLE OF scarr WITH UNIQUE KEY carrid. Example 3 : DATA: itab TYPE TABLE OF scarr.
  • 7. Defining Internal Tables: Sorted & Hashed
  • 8. Work Area or Header Line You can define internal tables either with (addition WITH HEADER LINE) or without header lines. An internal table with a header line consists of a work area (header line) and the actual table body. You address both objects using the same name . Reading an Internal Table using LOOP. LOOP at itab INTO wa. LOOP at itab. WRITE wa-carrid. WRITE itab-carrid. ENDLOOP. ENDLOOP.
  • 9. Hashed Internal Table Access to a hashed table is implemented using a hash algorithm. This means that the data records are distributed randomly but evenly over a particular memory area. Their addresses are stored in a separate table, the hash table . The hash function uses the key data to calculate the address where the hashed table entry is located. If a single record is accessed using a fully specified key, the hash function can use the key immediately to determine the address of the hashed table entry. That is where the address of the actual data record is stored. Using a hash technique means that the access time no longer depends on the total number of entries in the table. The access time is therefore very short. Hashed tables are therefore particularly useful for large tables with which you predominantly use read access.
  • 10. Internal Table – single-record access Whenever you want to read individual table rows by declaring a complete key, use READ TABLE ... WITH TABLE KEY. This achieves the fastest single-record access with a key. If the table is a standard table the SAP system performs a sequential search. If the table is a sorted table the SAP system performs a binary search. If the table is a hashed table the SAP system applies the hashed algorithm.
  • 11. Internal Table Kinds - Summary Standard table Standard tables are best when you access data using an index, that is, the order of the data records is important but the sorting and the uniqueness are not crucial. If you decide you need to sort the table or access it using the key or a binary search, you can always program these functions by hand. Sorted table 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 use a binary search, you can always program these functions by hand. A sorted table also defines a unique key, but unlike a standard table, the data is sorted and then inserted. Also, the initial data is built up faster. Thus, if you have a table with few entries but lots of accesses that change the contents, a sorted table may be more efficient than a standard table in terms of runtime. A typical use is the preparation and execution of database changes by mass processing . The most efficient way of doing this is to create a local copy of the data in the program, make the changes to the copy, and then write all of its data records 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. Consequently, when you access the internal table, you should already use the unique key to ensure that the data record is unique. Automatic sorting can also bring further advantages.
  • 12. Internal Table Kinds - Summary Hashed table The hash algorithm calculates the address of an entry based on the key. This means that, with larger tables, the access time is reduced significantly in comparison with a binary search. But when you use a loop with a hashed table, the whole table has to be scanned. Because the data records are usually totally unsorted, a sorted table may be more useful if you have a loop over the beginning of a key. Alternatively, you could also sort the hashed table. Hashed table is only beneficial if you want to keep large amounts of data locally in the program and you mostly access it only to read it. You must ensure that you design your hashed table so that it is possible to specify the full key when you access it from your program. Typical use for hashed tables is for buffering or bundling large amounts of data from several database tables when an ABAP Dictionary view or a nested SELECT statement is not possible.

Editor's Notes

  • #5: The data type of an internal table is fully specified by its: Row type The row type defines the attributes of the individual columns. You normally enter a structure type, but any data type is possible. Key definition The key columns and their sequence determine the criteria by which the system identifies table rows. You can define the key as either UNIQUE or NON-UNIQUE. The uniqueness of the key must be compatible with the access type you have chosen for the table. If the key is unique, there can be no duplicate entries in the table. Access type Key access . like database tables . works via field contents. Example: Using the search term UA 0007 for read access to an internal table with the unique key CARRID CONNID and data as specified above will result in exactly one data record. Index access , unlike for database tables, the system assigns row numbers to certain kinds of internal tables. This means that you can sometimes use the index to access rows in the table. Example: Read-access to the data record with index 5 returns the fifth data record from the internal table.
  • #6: Standard tables are the most flexible kind. The flexibility occurs because the sort sequence of a standard table is not fixed. You can change it several times and resort the internal table’s contents accordingly. They are usually used with index access, however when used with key access, the system searches all lines sequentially for the key value. The average search time is proportional to the number of lines. Sorted tables are ideally used with unique keys and fixed sorting. When a sorted table is defined, either a unique or non-unique key must be defined. By definition, this key also determines the sorting order, it cannot be changed. When a key access is made using this key, the SAP system will automatically use a binary search technique. Sorted tables are especially useful for the loop processing of an entire internal table’s content in a fixed order. Hashed tables are not intended for loop processing. Instead, you would use it when you need to access one specific entry at a time of an internal table’s contents. In a key access to a hashed table, the SAP system calculates the position of the line from the key value using a hash function . The search time is not affected by the number of lines and always constant. Can be used for buffering or bundling large amounts of data from several DB tables. Refer to access times for 3 table kinds - Keller & Kruger Fig 4.17 Pg 177
  • #7: Example 1: The example shows the definition of a STANDARD internal table (TT_DISTANCE) using a local table kind (TT_DISTANCE_TY), which itself uses a local row type (S_DISTANCE_TY). Therefore, the defined internal standard table has the columns CARRID, CONNID, DISTANCE, and DISTID. The DEFAULT KEY means that all non-numeric fields are used to create the key. They are used in the sequence in which they occur in the row type. In this case, the keys CARRID, CONNID, and DISTID are defined. The key is non-unique. Example 2: The example shows the definition of a STANDARD internal table (itab) using a global row type (scarr). The defined internal standard table has the same columns as the DB table scarr. The KEY is defined as CARRID and is unique. Example 3: The example defaults to a STANDARD internal table WITH NON-UNIQUE DEFAULT KEY NOTE: No work area has been defined in these examples. This will be demonstrated later.
  • #8: The above example shows the definition of a sorted table and a hashed table. Both tables have the same row type as the standard table on the previous slide. Note that the contents of the tables are in a different order. For sorted tables, the sequence of the entries in the internal table is determined by the sequence of the fields in the key definition. For table kinds defined in a program, you can use the optional INITIAL SIZE addition to specify the number of rows that the runtime system should reserve when it instantiates the data object. INITIAL SIZE replaces the OCCURS statement.
  • #9: You can define internal tables either with (addition WITH HEADER LINE) or without header lines. An internal table with a header line consists of a work area (header line) and the actual table body. You address both objects using the same name . Note 1: Work area can be also defined as DATA: wa LIKE LINE OF scarr. Note 2: Reading an Internal Table using LOOP and WA
  • #10: Access to a hashed table is implemented using a hash algorithm. Simplified, this means that the data records are distributed randomly but evenly over a particular memory area. Their addresses are stored in a separate table, the hash table . The hash function uses the key data to calculate the address where the hashed table entry is located. The function is not injective, that is, there can be several data records stored at a single address. This is implemented internally as a chained list. Thus, the system may still have to search through such an area sequentially. However, the chained list can contain no more than two entries. If a new key leads to the same hashed table address for a third time, the system uses a changed hash function and rebuilds the management from scratch. The slide image illustrates the simplest case, that is, in which there is only one data record stored at each address. If a single record is accessed using a fully specified key, the hash function can use the key immediately to determine the address of the hashed table entry. That is where the address of the actual data record is stored. Using a hash technique means that the access time no longer depends on the total number of entries in the table. The access time is therefore very short. Hashed tables are therefore particularly useful for large tables with which you predominantly use read access. Data records are not inserted into the table in a sorted order. As with standard tables, you can sort hashed tables using the SORT statement - Sorting the table can be useful if you later want to use a loop to access the table.
  • #11: Demo zbmcLec009a zbmcLec009b zbmcLec009c
  • #13: Demo Workshop Exercises