Hello,

Sign up to join our community!

Welcome Back,

Please sign in to your account!

Forgot Password,

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

You must login to ask a question.

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

SAP EWM Help Latest Questions

  • 0
  • 0
DPM125
Beginner

How to use FIELD-SYMBOLS for dynamic access to internal tables in ABAP?

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.
TYPESBEGIN OF ty_employee,
         emp_id   TYPE i,
         emp_name TYPE string,
       END OF ty_employee.

DATAit_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

ConceptDescription
FIELD -SYMBOLSPointer-like dynamic variable in ABAP
ASSIGNUsed to assign memory reference
ASSIGN COMPONENTAccess structure fields by name at runtime
ANY TypeUse 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

Related Questions

Leave an answer

Leave an answer