Everybody hates field symbols and that is generally the story until they use it. Field symbols are not only better in terms of performance, they are life saviors in certain situations – like when being used to read global variables in exits and routines.
As the name suggests, field symbols are placeholders for other fields. They technically don’t occupy a space but point to a data object that has been declared. C Developers can identify with pointers.
DATA: lt_bseg TYPE STANDARD TABLE OF bseg.
FIELD-SYMBOLS : <fs_table> TYPE ANY , <fs_bseg> TYPE bseg .
Populate lt_bseg and then assign Field Symbol to lt_bseg.
ASSIGN : lt_bseg TO <fs_table> .
Now, loop at fs_table which will essentially be a loop on lt_bseg and any modification will modify the internal table.
LOOP AT <fs_table> ASSIGNING <fs_bseg> .
“modify value of fs_bseg which will change value of fs_table.
UNASSIGN <fs_table> .
UNASSIGN <fs_bseg> .
Different examples of declaration –
- FIELD-SYMBOLS : <field_symbol> TYPE <table-field>.
- FIELD-SYMBOLS : <field_symbol> TYPE <table>.
- FIELD-SYMBOLS : <field_symbol> TYPE REF TO DATA .
Advantages of using FS –
- Performance improvement when compared to Work Area.
- Modification within Loop is simpler.
- Can be used for dynamic assignment even when the variable is defined during runtime only.