Internal Tables Part 6: APPEND, INSERT, MODIFY, DELETE and COLLECT
Preview · a free account unlocks the full lesson
Change 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.
In this lessonShow sectionsHide sections
Visual overview
Explanation
Parts 1 through 5 covered reading internal tables; now it's time to change them. To add rows, APPEND gs_flight TO gt_flight adds a row at the end, which works for standard tables (and sorted tables as long as the resulting order stays correct).
INSERT gs_flight INTO TABLE gt_flight is more generic: for a standard table it adds at the end, for a sorted table it finds the correct position, and for a hashed table it inserts by key — and with unique keys, a duplicate simply isn't inserted, leaving sy-subrc at 4.
INSERT gs_flight INTO gt_flight INDEX 1 inserts at a specific position in standard or sorted tables, APPEND LINES OF gt_other TO gt_flight appends an entire other table at once, and the modern functional style gt_flight = VALUE #( BASE gt_flight ( ... ) ) achieves the same result inline.
To change rows, the preferred approach is usually a loop using field symbols, as covered in Part 3. Where that doesn't fit, MODIFY gt_flight FROM gs_flight INDEX lv_tabix changes a single row by its index, MODIFY TABLE gt_flight FROM gs_flight changes a row located by its table key (for sorted or hashed tables), and MODIFY gt_flight FROM gs_upd TRANSPORTING price WHERE carrid = 'LH' changes many matching rows at once, touching only the listed fields.
Create a free account to keep reading
You have read the opening of this lesson. A free ERPClimb account unlocks the rest of it, every other lesson and topic, and your learning history, so you can pick up exactly where you stopped. No card needed.
- Full explanation
- Code example
- Real project scenario
- Common mistakes
- Best practices
- Interview angle
One tap with Google works too. Every topic keeps its first lesson open to everyone.
Keep exploring
Check before use: lesson examples are educational, not a guarantee of correctness for your SAP edition or release. Sample code has not been executed on your SAP system. Confirm API availability, syntax, authorizations and business impact in an approved development or test environment.