FIELD-SYMBOLS are like pointers in other programming languages. They don’t store data themselves but rather point to memory locations dynamically. This is especially useful when you don’t know the field or structure you’re working with until runtime.
Step 1: Declare an internal table and fill it
REPORT zclass_test_dp.
TYPES: BEGIN OF ty_employee,
emp_id TYPE i,
emp_name TYPE string,
END OF ty_employee.
DATA: it_employees TYPE STANDARD TABLE OF ty_employee,
wa_employee TYPE ty_employee.
wa_employee-emp_id = 101.
wa_employee-emp_name = 'John'.
APPEND wa_employee TO it_employees.
wa_employee-emp_id = 102.
wa_employee-emp_name = 'Alice'.
APPEND wa_employee TO it_employees.
field-symbols: <fs_line> type ty_employee,
<fs_field> type any.
LOOP AT it_employees ASSIGNING <fs_line>.
ASSIGN COMPONENT 'EMP_NAME' OF STRUCTURE <fs_line> TO <fs_field>.
IF sy-subrc = 0.
WRITE: / 'Employee Name:', <fs_field>.
ENDIF.
ENDLOOP. Output:
What’s Happening Here?
- ASSIGNING <fs_line> lets us avoid copying the whole structure — we just point to it.
- ASSIGN COMPONENT allows dynamic accessing a specific field by name, like ‘EMP_NAME’.
- <fs_field> can now be used to read or modify that field.
Summary
| Concept | Description |
| FIELD -SYMBOLS | Pointer-like dynamic variable in ABAP |
| ASSIGN | Used to assign memory reference |
| ASSIGN COMPONENT | Access structure fields by name at runtime |
| ANY Type | Use for unknown/dynamic field types |
Used heavily in:
- Dynamic ALV reporting
- Generic data processing
- Dynamic field mapping
- Frameworks like BOPF or RAP where field names are metadata-driven
