Internal Tables Part 3: Work Area vs Field Symbol vs Data Reference
Understand 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.
Explanation
📌 KEY POINTS
✅ INTO wa copies the row; changes need MODIFY to go back into the table.
✅ ASSIGNING <fs> points directly at the row; changes are immediate — no MODIFY, no copy.
✅ REFERENCE INTO lr stores a pointer you can keep (e.g. in another table).
⚠️ Check IS ASSIGNED / IS BOUND before use; never change key fields of sorted/hashed tables via <fs>.
━━━━━━━━━━━━━━━━━━━━
▶ WHERE WE ARE
Parts 1–2 read rows into work areas. For changing data and for large tables, the access technique matters.
━━━━━━━━━━━━━━━━━━━━
▶ 1. WORK AREA (COPY)
LOOP AT gt_flights INTO gs_flight.
gs_flight-price = gs_flight-price * '1.1'.
MODIFY gt_flights FROM gs_flight. " write back (index of current loop row)
ENDLOOP.
- Safe and simple; the table changes only with MODIFY.
- Costs a copy per row — noticeable for wide rows or big tables.
━━━━━━━━━━━━━━━━━━━━
▶ 2. FIELD SYMBOL (POINTER-LIKE)
FIELD-SYMBOLS <ls_flight> TYPE ty_flight.
LOOP AT gt_flights ASSIGNING <ls_flight>.
<ls_flight>-price = <ls_flight>-price * '1.1'. " changes the table row directly
ENDLOOP.
- No copy, no MODIFY — fastest for changes.
- After a failed READ … ASSIGNING, the field symbol is not assigned → check IS ASSIGNED.
- Don't modify key fields of sorted or hashed tables (runtime error).
━━━━━━━━━━━━━━━━━━━━
▶ 3. DATA REFERENCE
DATA lr_flight TYPE REF TO ty_flight.
LOOP AT gt_flights REFERENCE INTO lr_flight.
lr_flight->price = lr_flight->price * '1.1'.
ENDLOOP.
- Like a field symbol, but a variable: can be stored, passed and put into tables of references.
- Check IS BOUND before dereferencing.
━━━━━━━━━━━━━━━━━━━━
▶ 4. WHICH ONE WHEN
- Read-only, small rows → work area (clear and simple).
- Changing rows in a loop → field symbol.
- Need to remember rows for later (e.g. link objects) → data reference.
- Very wide rows (hundreds of fields) and large tables → field symbol even for reading.
━━━━━━━━━━━━━━━━━━━━
▶ 5. READ TABLE VARIANTS
READ TABLE gt_flights INTO gs_flight WITH KEY … (copy)
READ TABLE gt_flights ASSIGNING <ls_flight> WITH KEY … (point)
READ TABLE gt_flights TRANSPORTING NO FIELDS WITH KEY … (existence check only, sy-subrc/sy-tabix)
━━━━━━━━━━━━━━━━━━━━
▶ STEP BY STEP
- Run the three loops in the code example on SFLIGHT data.
- Compare runtimes with GET RUN TIME.
- Try a READ … ASSIGNING that fails and see the IS ASSIGNED check.
💡 Modern syntax (7.40+): LOOP AT … ASSIGNING FIELD-SYMBOL(<fs>), REFERENCE INTO DATA(lr).
✅ CHECKPOINT: you choose the access technique consciously and change tables without unnecessary copies.
Code example
REPORT zitab_access. TYPES: BEGIN OF ty_flight, carrid TYPE s_carr_id, connid TYPE s_conn_id, fldate TYPE s_date, price TYPE s_price, END OF ty_flight. DATA: gt_flights TYPE STANDARD TABLE OF ty_flight, gs_flight TYPE ty_flight, lr_flight TYPE REF TO ty_flight.FIELD-SYMBOLS <ls_flight> TYPE ty_flight. START-OF-SELECTION. SELECT carrid connid fldate price FROM sflight INTO TABLE gt_flights. * ===== 1. Work area: copy + MODIFY ===== LOOP AT gt_flights INTO gs_flight WHERE carrid = 'LH'. gs_flight-price = gs_flight-price * '1.05'. MODIFY gt_flights FROM gs_flight TRANSPORTING price. " write back current row ENDLOOP. * ===== 2. Field symbol: direct change, no MODIFY ===== LOOP AT gt_flights ASSIGNING <ls_flight> WHERE carrid = 'AA'. <ls_flight>-price = <ls_flight>-price * '1.05'. ENDLOOP. * ===== 3. Data reference: can be stored and passed ===== DATA lt_expensive TYPE STANDARD TABLE OF REF TO ty_flight. LOOP AT gt_flights REFERENCE INTO lr_flight. IF lr_flight->price > 1000. APPEND lr_flight TO lt_expensive. " remember the row itself ENDIF. ENDLOOP. * ===== READ with ASSIGNING: always check ===== UNASSIGN <ls_flight>. READ TABLE gt_flights ASSIGNING <ls_flight> WITH KEY connid = '9999'. IF <ls_flight> IS ASSIGNED. <ls_flight>-price = 0. ELSE. WRITE: / 'Connection 9999 not found - nothing changed'. ENDIF. * ===== Existence check without copying ===== READ TABLE gt_flights TRANSPORTING NO FIELDS WITH KEY carrid = 'UA'. IF sy-subrc = 0. WRITE: / 'UA flights exist, first at index', sy-tabix. ENDIF.Real project scenario
A pricing update program looped over 1.5 million condition records INTO a work area and used MODIFY for every row. The job ran for 40 minutes and used a lot of memory copying 120-field rows.
Switching to LOOP … ASSIGNING with direct field changes removed both the copies and the MODIFY statements. Runtime dropped to under 10 minutes with identical results. A code review rule was added: "changing loops use field symbols".
Common mistakes
- Changing a work area and forgetting MODIFY.
- Using a field symbol after a failed READ without IS ASSIGNED.
- Changing key fields of sorted/hashed tables through field symbols.
- Dereferencing an unbound data reference.
- Copying wide rows into work areas in large loops.
Best practices
- Use field symbols for changing loops and large tables.
- Use work areas for simple, read-only processing.
- Use data references when rows must be stored or passed.
- Check IS ASSIGNED / IS BOUND.
- Use TRANSPORTING NO FIELDS for pure existence checks.
Interview angle
Questions: "Difference between work area and field symbol?", "Why use ASSIGNING in loops?", "When use REFERENCE INTO?"
Strong answer: INTO copies the row (needs MODIFY to change the table), ASSIGNING points to the row (changes are direct, no copy — faster), REFERENCE INTO provides a storable pointer; check IS ASSIGNED/IS BOUND; do not change keys of sorted/hashed tables; use TRANSPORTING NO FIELDS for existence checks.
Practice this lesson
Quick check
1. A loop uses LOOP AT itab INTO wa and changes wa. What happens to the table?
2. Which construct loops with a field-symbol to avoid row copies?
3. When using LOOP AT itab REFERENCE INTO dref to process a STANDARD table, what does the variable dref represent for each loop pass?
Interview questions
1. When do you use a work area, a field symbol or a data reference to access table rows?
Answer it in your own words first, then compare.
2. What is the difference between LOOP AT itab INTO wa and LOOP AT itab ASSIGNING <fs>? Why does this distinction matter for performance?
Answer it in your own words first, then compare.
Reference-verified: the steps are checked against official SAP documentation and tutorials, and object and field names in the sample code are checked for consistency. The code has not been compiled or run on an SAP system by ERPClimb. Syntax marked release-dependent varies by SAP release, so check it in your own system.
More lessons in this topic
- Internal Tables Part 1: Standard, Sorted and Hashed Tables
- Internal Tables Part 10: Memory Management and Large Internal Tables
- Internal Tables Part 2: Choosing the Right Table Type
- Internal Tables Part 4: READ TABLE, sy-subrc and Table Expressions
- Internal Tables Part 5: SORT, BINARY SEARCH and Secondary Keys
- Internal Tables Part 6: APPEND, INSERT, MODIFY, DELETE and COLLECT
- Internal Tables Part 7: Removing Duplicates and Building Unique Datasets
- Internal Tables Part 8: LOOP Patterns — WHERE, Control Levels and Totals