Can someone simply explain me what happen in field symbols ABAP? I'm glad if someone can explain the concept and how does it related to inheritance and how does it increasing the performance.
-
1possible duplicate of [Field symbol and Data reference in SAP-ABAP](http://stackoverflow.com/questions/12402564/field-symbol-and-data-reference-in-sap-abap) – vwegert May 26 '14 at 10:22
3 Answers
Field Symbols can be said to be pointers. Means, if You assign anything to a fields-symbol, the symbol is strong coupled ( linked ) to the variable, and any change to the fieldsymbol will change the variable immediately. In terms of performance, it comes to use, if You loop over an internal table. Instead of looping into a structure, You can loop into a fieldsymbol. If modifications to the internal table are made, then You can directly modify the fieldsymbol. Then You can get rid of the "modify" instruction,which is used in order to map the changes of the structure back to the corresponding line of the internal table. "Read Table assigning" also serves the same purpose, like looping into a field-symbol. Field-Symbol are more recommended then using a "workarea" ( when modifying ) , but references are the thing to go for now. They work almost similar to fieldsymbols. Could I clarify it for You ?

- 1,831
- 1
- 17
- 27
-
There are benefits in terms of memory usage as well. You aren't creating another variable or work area as you are pointing at the original. – Dan Oct 28 '16 at 02:36
Field-symbols in ABAP works as pointers in C++. It has a lot of benefits:
- Do not create extra-variables.
- You can create a type ANY field-symbol, so you can point to any variable/table type memory space.
- ...
I hope these lines would be helpful.

- 86
- 7
Let's have a look at it when it comes to coding. Additionally i would like to throw in data references.
* The 'classic' way. Not recommended though.
LOOP AT lt_data INTO DATA(ls_data).
ls_data-value += 10.
MODIFY TABLE lt_data FROM ls_data.
ENDLOOP.
* Field symbols
LOOP AT lt_data ASSIGNING FIELD-SYMBOL(<fs_data>).
<fs_data>-value += 10.
ENDLOOP.
* Data references
LOOP AT lt_data REFERENCE INTO DATA(lr_data).
lr_data->value += 10.
ENDLOOP.
I personally prefer data references, because they go hand in hand with the OO approach. I have to admit that field symbols are slightly in front when it comes to performance.
The last two should be preferred when talking about modifying. The first example has an additional copy of data which decreases overall performance.

- 3
- 4