Internal tables are the central data structure in ABAP. Most of what an ABAP program does is manipulate them.
Three kinds
| Kind | Key | Search | Duplicates | Use |
|---|---|---|---|---|
| STANDARD | Non-unique | Linear | Allowed | Sequential processing, index access |
| SORTED | Unique or non-unique | Binary | Configurable | Frequent key lookups, always sorted |
| HASHED | Unique required | Hash | Not allowed | Fast lookup by full key |
Adding rows
APPEND ls_item TO lt_items.
INSERT ls_item INTO TABLE lt_sorted.
APPEND LINES OF lt_source TO lt_target.
DATA(lt_items) = VALUE ty_items(
( matnr = 'MAT-001' menge = 10 )
( matnr = 'MAT-002' menge = 20 ) ).APPEND is not available on sorted or hashed tables, because position is determined by the key rather than by insertion order.
Reading rows
READ TABLE lt_items INTO ls_item WITH KEY matnr = 'MAT-001'.
IF sy-subrc = 0.
ENDIF.
READ TABLE lt_items ASSIGNING FIELD-SYMBOL(<fs>) WITH KEY matnr = 'MAT-001'.
READ TABLE lt_items TRANSPORTING NO FIELDS WITH KEY matnr = 'MAT-001'.
DATA(ls_found) = lt_items[ matnr = 'MAT-001' ].Changing and deleting
MODIFY lt_items FROM ls_item TRANSPORTING menge WHERE matnr = 'MAT-001'.
DELETE lt_items WHERE menge = 0.
SORT lt_items BY matnr.
DELETE ADJACENT DUPLICATES FROM lt_items COMPARING matnr.
CLEAR lt_items.
FREE lt_items.Aggregating
SORT lt_items BY matnr.
LOOP AT lt_items INTO ls_item.
AT NEW matnr.
lv_subtotal = 0.
ENDAT.
lv_subtotal = lv_subtotal + ls_item-menge.
AT END OF matnr.
WRITE: / ls_item-matnr, lv_subtotal.
ENDAT.
ENDLOOP.
DATA(lv_total) = REDUCE i( INIT s = 0
FOR ls IN lt_items
NEXT s = s + ls-menge ).