ABAP Internal Table Declaration Generator
Choosing between standard, sorted and hashed internal tables decides the speed of every READ TABLE in your program. This generator writes the declaration for the kind and key you pick, a matching local type, and the READ, LOOP and DELETE statements that go with it.
Fill in
HASHED tables must be UNIQUE. STANDARD tables must be NON-UNIQUE.
Space separated field names.
1. Declaration with a DDIC line type
DATA lt_items TYPE SORTED TABLE OF mara WITH UNIQUE KEY matnr.
2. Declaration with a local line type
TYPES: BEGIN OF ty_line,
matnr TYPE matnr,
maktx TYPE maktx,
menge TYPE menge_d,
END OF ty_line.
DATA lt_items TYPE SORTED TABLE OF ty_line
WITH UNIQUE KEY matnr.3. Common operations
* Read one row by key READ TABLE lt_items ASSIGNING FIELD-SYMBOL(<ls_row>) WITH KEY matnr = lv_matnr. IF sy-subrc = 0. * <ls_row> points at the row, changes are written to the table ENDIF. * Loop without copying rows LOOP AT lt_items ASSIGNING FIELD-SYMBOL(<ls_item>). * use <ls_item>-field here ENDLOOP. * Delete by key DELETE lt_items WHERE matnr = lv_matnr. * Standard tables only: sort and remove duplicates * SORT lt_items BY matnr. * DELETE ADJACENT DUPLICATES FROM lt_items COMPARING matnr.
Rules the compiler enforces: HASHED tables need a UNIQUE key, STANDARD tables only allow NON-UNIQUE, and SORT and DELETE ADJACENT DUPLICATES are meant for standard tables. Replace the sample local type with your own components. Inline FIELD-SYMBOL(...) needs ABAP 7.40 SP02 or later.
Review a performance-sensitive program
Send us a slow custom program and we will describe where the table access pattern could improve.
Optional. The tool and every export work without this. No spam.
How to use it
Pick the variable name, the DDIC structure or your own line type, the table kind and the key fields. The first block gives the one-line DATA declaration. The second block shows the same table with a local TYPES structure, which is what you use when only some fields are needed. The third block gives the statements you will write next. Copy what you need, rename the lookup variable and replace the example components with your own.
Standard, sorted or hashed: which to choose
A standard table is read by linear search unless you SORT it and use BINARY SEARCH, so it suits small tables and sequential processing. A sorted table keeps rows in key order and uses binary search on the key, which is the best default when you need ordered access and partial key reads. A hashed table gives constant time access on the full unique key, which is best for large lookup tables read by exact key and never processed in order. Choose by the access pattern, not by habit.
- Standard: append and loop, small lookups
- Sorted: ordered reads and range access by key prefix
- Hashed: large tables read only by full unique key
Field symbols, references and copies
LOOP AT with ASSIGNING gives a pointer to the table row, so there is no copy and changes write straight into the table. Use INTO when you want a work area copy. For wide rows, such as full MARA lines, ASSIGNING is noticeably cheaper. READ TABLE with WITH KEY on a sorted or hashed table is optimised when the key fields match the table key, so use WITH TABLE KEY if you want the compiler to insist on that.
Common mistakes
Frequent errors are reading a big standard table inside a loop without sorting and binary search, declaring a hashed table with a non-unique key, expecting insertion order from a sorted table, and deleting rows while looping with an index. Also check sy-subrc after every READ TABLE, because an unchecked failed read leaves the previous field symbol assignment untouched in older code.
Frequently Asked Questions
Which internal table type is fastest?
It depends on how you read it. A hashed table is fastest for exact lookups on the full unique key. A sorted table is fast for key or partial-key reads and ordered loops. A standard table is fine for small data or when you read it once from top to bottom.
Why do I get a syntax error for UNIQUE KEY on a standard table?
Standard tables have no uniqueness check because rows are appended without lookup, so only a NON-UNIQUE key is allowed. If you need uniqueness, use a sorted or hashed table, or remove duplicates yourself with DELETE ADJACENT DUPLICATES after sorting.
What does WITH DEFAULT KEY do?
It uses all character-like and byte-like components as the key. It is common in older code, but it is not recommended for new code, and the SAP code inspector flags it. Name the key fields you actually need instead.
Should I use ASSIGNING or INTO in a LOOP?
ASSIGNING avoids copying the row and allows direct changes, so it is usually better for wide rows. INTO copies each row into a work area, which is safer if you do not want to modify the table. Both are valid, choose on intent and row width.
If your ABAP is mostly moving ERP data into tables for reports, we can show how a governed read-only layer answers the same questions without new development.
Related Tools
ABAP SELECT Statement Generator
Fill in table, fields and a WHERE condition and get modern ABAP Open SQL: SELECT INTO TABLE, SELECT SINGLE and a safe FOR ALL ENTRIES pattern.
SAPABAP ALV Report Skeleton Generator
Enter a program name, table and selection field and get a working ABAP report that shows an ALV grid using CL_SALV_TABLE.
SAPABAP Naming Convention Template
A fill-in development standard that defines prefixes for variables, parameters, classes, DDIC objects, programs and CDS views.
SAPABAP Code Review Checklist
A practical review checklist for ABAP changes: database access, security, error handling, structure and S/4HANA compatibility.
More SAP tools
See all- SAP Sales Document Types Reference
- SAP Pricing Procedure Design Worksheet
- SAP Item Category Determination Reference
- SAP Delivery Block Reasons Template
- SAP Credit Management Checklist
- SAP Output Determination Checklist
- SAP Billing Types Reference
- SAP Incompletion Log Checklist
- SAP SD Tables Reference (VBAK, VBAP, LIKP, VBRK and More)