Although references to data and field symbols look very similar and are often used in a similar way (see other answers), they are fundamentally different.
Data references are variables that store a value, just like a string or an integer. They have a fixed size in memory and content. The only difference is that these links are pointers to other data objects, i.e. e. content is of particular importance. They cannot point anywhere, they can be dereferenced, you can pass them to other routines, you can manipulate a pointer ( GET REFERENCE ) or the value that it points to. There is nothing special about this - just pointers, as you know, from your favorite programming language.
Field characters are not βrealβ variables. The documentation states that
They do not physically reserve space for the field
Field symbols are really just smart manipulations with the local symbol table of the ABAP virtual machine. I will try to illustrate this - note that this is a very simplified model. Let's say you declare three variables:
DATA: my_char TYPE c, my_int TYPE i, my_ref TYPE REF TO i.
Then the symbol table will contain, among other things, entries that may look like this:
name type size addr ------------------------------ MY_CHAR c 1 0x123456 MY_INT i 4 0x123457 MY_REF r ? 0x123461
(I'm not sure about the actual size of the reference variable.)
These entries indicate only the address containing the values. Depending on the volume of these variables, they can be in completely different areas of memory, but this is not our problem at the moment. Important points:
- Memory should be reserved for variables (this is done automatically, even for references).
- Links work just like all other variables.
Add a field character to this:
FIELD-SYMBOLS: <my_fs> TYPE any.
Then the symbol may look like this:
name type size addr target -------------------------------------- MY_CHAR c 1 0x123456 MY_INT i 4 0x123457 MY_REF r ? 0x123461 <MY_FS> *
The field symbol is created in its initial state (not assigned). It does not indicate anywhere, and using it in this state will result in a short dump. Important point: It is not supported by heap memory, like other variables. let's
ASSIGN my_char TO <my_fs>.
Again the symbol might look like this:
name type size addr target -------------------------------------- MY_CHAR c 1 0x123456 MY_INT i 4 0x123457 MY_REF r ? 0x123461 <MY_FS> * MY_CHAR
Now, when accessing <my_fs> , the runtime system recognizes it as a field symbol, searches for the current target in the symbol table, and redirects all operations to the actual location of my_char . If, on the other hand, you have to issue a command
GET REFERENCE OF my_int INTO my_ref.
the character table would not change, but on the "heap address" 0x123461 you will find the "address" 0x123457. Just assigning a value, for example my_char = 'X' or my_int = 42 * 2 .
In the simplified version, why you cannot pass field characters as changing parameters and allow them to be reassigned inside a subprogram . They do not exist in the same way as other variables, and they do not matter outside the scope of the symbol table to which they were added.