ABAPIntermediate
Internal Tables
Master standard, sorted and hashed internal tables with real ABAP performance, debugging and interview scenarios.
Overview
Master standard, sorted and hashed internal tables with real ABAP performance, debugging and interview scenarios.
Lessons in this topic
- Internal Tables Part 1: Standard, Sorted and Hashed TablesUnderstand internal tables from the ground up: what they are, the line type and the table key, the three table kinds (standard, sorted, hashed), work areas, and filling and reading a table from SFLIGHT in a classic report.
- Internal Tables Part 2: Choosing the Right Table TypePick STANDARD, SORTED or HASHED tables by access pattern: index access, key reads, range processing, uniqueness and data volume — with a decision table and measured examples.
- Internal Tables Part 3: Work Area vs Field Symbol vs Data ReferenceUnderstand the three ways to access table rows — copying into a work area, pointing with a field symbol (ASSIGNING), or referencing with REFERENCE INTO — and when each is correct and fast.
- Internal Tables Part 4: READ TABLE, sy-subrc and Table ExpressionsRead single rows correctly: READ TABLE by index, by key and with TABLE KEY, TRANSPORTING NO FIELDS for existence checks, sy-subrc and sy-tabix — and the modern table expressions with OPTIONAL and DEFAULT.
- Internal Tables Part 5: SORT, BINARY SEARCH and Secondary KeysMake key reads fast on standard tables with SORT and BINARY SEARCH, understand why the sort order must match, and use secondary keys when one table needs several access paths.
- Internal Tables Part 6: APPEND, INSERT, MODIFY, DELETE and COLLECTChange internal tables correctly: APPEND vs INSERT for each table kind, MODIFY by index or with WHERE, DELETE single rows, ranges and WHERE conditions, COLLECT for totals, and APPEND LINES for whole tables.
- Internal Tables Part 7: Removing Duplicates and Building Unique DatasetsRemove duplicate rows reliably: SORT + DELETE ADJACENT DUPLICATES with COMPARING, unique-key tables, collecting unique keys for FOR ALL ENTRIES, and the modern GROUP BY alternative.
- Internal Tables Part 8: LOOP Patterns — WHERE, Control Levels and TotalsProcess tables with the right loop pattern: LOOP WHERE, control-level processing with AT FIRST/AT NEW/AT END OF/SUM, FROM/TO ranges, and modern GROUP BY, VALUE FOR and REDUCE.
- Internal Tables Part 9: Nested LOOP Optimization and Parallel CursorFix the most common ABAP performance problem — nested loops over two large tables — with sorted tables and LOOP WHERE, hashed lookups, and the classic parallel cursor technique.
- Internal Tables Part 10: Memory Management and Large Internal TablesProcess large data volumes without memory dumps: estimate table size, select only needed columns, process in packages, free memory with FREE, avoid unnecessary copies, and analyze memory with the debugger and memory inspector.
Interview questions covered
- What is the difference between LOOP AT itab INTO wa and LOOP AT itab ASSIGNING <fs>? Why does this distinction matter for performance?
- A background job processes a large internal table and occasionally dumps with a short dump related to memory exhaustion, but only when run against certain company codes with more data. What internal-table-specific patterns would you look for in the code as likely culprits?
- You need to build an internal table structure to hold sales order header data along with a variable number of item lines per order (a nested/hierarchical structure). How would you model this using internal tables?
- What does the BINARY SEARCH addition do in a READ TABLE statement, and what precondition must be met for it to work correctly?
- A program uses APPEND to add rows into what was declared as a SORTED table, and it throws a runtime error intermittently only for certain input data. What's happening and how would you fix it?
- How would you design internal table processing for a framework method that must merge data from multiple heterogeneous sources (different internal tables with overlapping but not identical structures) into one consolidated result table, while keeping the design extensible for future new sources?
- A custom program compares two internal tables (an 'old' snapshot and a 'new' snapshot of the same business data) to identify inserted, deleted, and changed records for a delta interface. How would you design this comparison efficiently using internal tables?
- Your program builds an internal table of open purchase order items and needs to compute a running total per vendor, then also needs the final list sorted by vendor with a subtotal line after each vendor's items. How would you design the internal table structures and logic for this?
- Your team is designing a reusable class method that accepts an internal table as an importing parameter and must work regardless of whether the caller passes a standard, sorted, or hashed table. What design considerations are important here?
- You inherited a program where a field symbol is assigned inside a loop using ASSIGN COMPONENT idx OF STRUCTURE wa TO <fs>, and occasionally the program dumps with an 'unassigned field symbol' error only for certain input files. How would you debug this?
- A high-throughput interface program processes internal tables with several hundred thousand rows and needs to remove duplicate rows based on a subset of fields, not the full row. What internal table techniques would you use to do this efficiently, and what pitfalls exist with the standard DELETE ADJACENT DUPLICATES approach?
- You are asked to redesign a poorly performing report that builds an ALV output by looping over a header internal table and, for each header, looping over a full standard items internal table using a WHERE condition to find matching items (LOOP AT items WHERE vbeln = header-vbeln). What internal table redesign would you propose and why?
- A report using SELECT ... FOR ALL ENTRIES IN lt_driver sometimes returns fewer rows than expected, and investigation shows lt_driver had duplicate key values before the SELECT. What internal-table-related behavior explains this and how would you fix the underlying program?
- What are the three types of internal tables in ABAP (Standard, Sorted, Hashed) and how do they differ in terms of key definition and access?
- In a debugging session, you find that a program modifies rows of an internal table inside a LOOP using MODIFY itab FROM wa, but some rows are not getting updated as expected even though the logic looks correct. What internal-table-specific issues would you investigate?
- You need to build a highly reusable internal table-based caching mechanism inside a long-running framework class, where thousands of different keys will be looked up repeatedly across many method calls without re-querying the database each time. What internal table design would you use and what pitfalls would you guard against?
- How would you decide between using a standard internal table with SORT + BINARY SEARCH versus declaring the table directly as a SORTED or HASHED table type, from a design and maintainability perspective?
- What is the purpose of a secondary key (secondary index) on an internal table, and how do you define one?
- A colleague wrote code that builds a RANGES-style selection table dynamically to filter a SELECT statement based on user input from a selection screen, but sometimes the filter behaves unexpectedly (returns too many or too few records). What internal table design aspects would you check?
- You need to process 2 million material master records in a background report, applying business logic per record and writing results to a Z-table. Reading all 2 million rows into a single internal table at once causes memory pressure. How would you redesign the internal table handling for this?