Accessing Structure Components Dynamically in ABAP
Learn how to access structure components dynamically in ABAP using the newer
Have you ever encountered a scenario where you needed to retrieve a specific component value from a dynamic structure? Traditionally, this is achieved using:
1
ASSIGN COMPONENT 'COMP_NAME' OF STRUCTURE <fs> TO FIELD-SYMBOL(<fs_value>).
However, the same can be achieved with the newer syntax:
1
2
3
4
ASSIGN <fs>-(comp_name) TO FIELD-SYMBOL(<fs_value>).
" Or with a work area
ASSIGN wa-(comp_name) TO FIELD-SYMBOL(<fs_value>).
Where comp_name is a variable containing the component name as a string — resolved dynamically at runtime.
For more details on dynamic programming in ABAP, refer to the ABAP Dynamic Programming Cheat Sheet.
This post is licensed under CC BY 4.0 by the author.
