Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.

Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.

Successfully reported this slideshow.

Like this presentation? Why not share!

1,289 views

Published on

No Downloads

Total views

1,289

On SlideShare

0

From Embeds

0

Number of Embeds

2

Shares

0

Downloads

150

Comments

0

Likes

3

No embeds

No notes for slide

- 1. Lecture 12 Advanced Internal Tables BCO5647 Applications Programming Techniques (ABAP)
- 2. Readings & Objectives <ul><li>Readings </li></ul><ul><li>Keller & Keller Chapter 4 Section 4.7.1 & 4.7.3 </li></ul><ul><li>Objectives This lecture will </li></ul><ul><li>Revise the structure of internal tables </li></ul><ul><li>Review the attributes of internal tables </li></ul><ul><li>Describe the three internal table kinds: standard, sorted, hashed </li></ul><ul><li>Examine the features and application of STANDARD internal tables </li></ul><ul><li>Examine the features and application of SORTED internal tables </li></ul><ul><li>Examine the features and application of HASHED internal tables </li></ul><ul><li>Distinguish between the use of work areas Vs header lines when processing internal tables </li></ul>
- 3. Internal Tables as Dynamic Data Objects <ul><li>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. </li></ul><ul><li>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. </li></ul>
- 4. Attributes of an Internal Table <ul><li>The data type of an internal table is fully specified by its: </li></ul><ul><li>Row type </li></ul><ul><ul><li>The row type defines the attributes of the individual columns. You normally enter a structure type, but any data type is possible. </li></ul></ul><ul><li>Key definition </li></ul><ul><ul><li>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. </li></ul></ul><ul><li>Access type </li></ul><ul><ul><li>Key access – like database tables – works via field contents. </li></ul></ul><ul><ul><li>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. </li></ul></ul>
- 5. Internal Table Kinds <ul><li>Internal Tables can be divided into three table kinds, depending on the possible access type required: </li></ul><ul><ul><li>Standard Tables – the row number is maintained internally. Both index and key access are possible. </li></ul></ul><ul><ul><li>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. </li></ul></ul><ul><ul><li>Hashed Tables – The runtime-optimized data records are maintained here. This requires a unique key. Hashed tables only allow for key access. </li></ul></ul>
- 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 <ul><li>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 . </li></ul><ul><li>Reading an Internal Table using LOOP. </li></ul><ul><li>LOOP at itab INTO wa. LOOP at itab. </li></ul><ul><li> WRITE wa-carrid. WRITE itab-carrid. </li></ul><ul><li>ENDLOOP. ENDLOOP. </li></ul>
- 9. Hashed Internal Table <ul><li>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. </li></ul><ul><li>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. </li></ul><ul><li>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. </li></ul>
- 10. Internal Table – single-record access <ul><li>Whenever you want to read individual table rows by declaring a complete key, use READ TABLE ... WITH TABLE KEY. </li></ul><ul><li>This achieves the fastest single-record access with a key. </li></ul><ul><li>If the table is a standard table the SAP system performs a sequential search. </li></ul><ul><li>If the table is a sorted table the SAP system performs a binary search. </li></ul><ul><li>If the table is a hashed table the SAP system applies the hashed algorithm. </li></ul>
- 11. Internal Table Kinds - Summary <ul><li>Standard table </li></ul><ul><ul><li>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. </li></ul></ul><ul><li>Sorted table </li></ul><ul><ul><li>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. </li></ul></ul><ul><ul><li>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. </li></ul></ul>
- 12. Internal Table Kinds - Summary <ul><li>Hashed table </li></ul><ul><ul><li>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. </li></ul></ul><ul><ul><li>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. </li></ul></ul><ul><ul><li>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. </li></ul></ul>

No public clipboards found for this slide

Be the first to comment