08-26-2012 6:31 PM
Hi team,
I am totally confused with the concept of field symbols. Some one said it is a pointer and some one says it is a place holder and so on...
I am not able to get the actual picture behind this concept. Could any one please explain with small examples and then i'll go for huge things. Thanks allot in advance.
Regards,
SUDHEER KUMAR CHUNDURU.
08-26-2012 11:39 PM
Hi Sudheer,
The concept is not straightfoward.
But, here are some basic facts.
A field symbol is Not a pointer. It is a value at address variable or in other words derefrenced variables.
Field Symbols are just like variables , with the exception that they do not have a memory address assgined to them when the program is loaded in memory and are free to latch on to any memory address- typically those of variables declared statically in the code ( or in advanced cases, dynamically allocated memory). If they are not generically typed then the type of the variable should match with the field symbol type.
Put simply. field symbols are used to modify the contents of a memory address ( variable ).
Ex : Data : l_int type i,
l_int1 type i.
field-symbols :<fs_int> type i.
l_int = 4. Statement does not throw an error , as the memory is allocated .
<fs_int> = 4. ->Statement throws a run time error, because the field symbol has not latched on to any memory.
assign ls_int to <fs_int>.
<fs_int> = 5. - No issues as the field symbol and the variable l_int are the same, the field symbol acts just like an alias.
Now, the value of l_int is also 5 as <fs_int> also modifies the same memory.
assign ls_int1 to <fs_int> -> now it acts as an alias for l_int1.
A pointer is a variable capable of handling memory addresses only.
Pointers are declared with the 'TYPE REF TO ' addition.
example :data: l_int_ref type ref to i. ->integer poiner,
l_int type i ->integer variable.
field-symbols : <fs_int> type i.
get reference of l_int into l_int_ref. ->now l_int_ref points to the memory address of the variable l_int..
You would typically use the field symbol to access the value at the address pointed to by l_int_ref.
You would do so by using the ->* operator- the de referencing operator.
.
Example : assign l_int_ref->* to <fs_int>.
Well , this is the best I could do, but the whole concept of memory allocations, variable and pointers are much more and cannot be covered in this post.
Try to see the contents of these different variables in the debugger and you would get a clearer picture.
I hope this helps.
Thanks,
Venkat.
08-26-2012 11:39 PM
Hi Sudheer,
The concept is not straightfoward.
But, here are some basic facts.
A field symbol is Not a pointer. It is a value at address variable or in other words derefrenced variables.
Field Symbols are just like variables , with the exception that they do not have a memory address assgined to them when the program is loaded in memory and are free to latch on to any memory address- typically those of variables declared statically in the code ( or in advanced cases, dynamically allocated memory). If they are not generically typed then the type of the variable should match with the field symbol type.
Put simply. field symbols are used to modify the contents of a memory address ( variable ).
Ex : Data : l_int type i,
l_int1 type i.
field-symbols :<fs_int> type i.
l_int = 4. Statement does not throw an error , as the memory is allocated .
<fs_int> = 4. ->Statement throws a run time error, because the field symbol has not latched on to any memory.
assign ls_int to <fs_int>.
<fs_int> = 5. - No issues as the field symbol and the variable l_int are the same, the field symbol acts just like an alias.
Now, the value of l_int is also 5 as <fs_int> also modifies the same memory.
assign ls_int1 to <fs_int> -> now it acts as an alias for l_int1.
A pointer is a variable capable of handling memory addresses only.
Pointers are declared with the 'TYPE REF TO ' addition.
example :data: l_int_ref type ref to i. ->integer poiner,
l_int type i ->integer variable.
field-symbols : <fs_int> type i.
get reference of l_int into l_int_ref. ->now l_int_ref points to the memory address of the variable l_int..
You would typically use the field symbol to access the value at the address pointed to by l_int_ref.
You would do so by using the ->* operator- the de referencing operator.
.
Example : assign l_int_ref->* to <fs_int>.
Well , this is the best I could do, but the whole concept of memory allocations, variable and pointers are much more and cannot be covered in this post.
Try to see the contents of these different variables in the debugger and you would get a clearer picture.
I hope this helps.
Thanks,
Venkat.
08-27-2012 6:12 AM
A field symbol is Not a pointer.
If i remember correctly somewhere i had read that Field-Symbols are "dereferenced pointers" & reference variables are analogous "pointers".
I think the author drew his conclusion from the de-referencing operation
Let me know your thoughts.
BR,
Suhas
Message was edited by: Suhas Saha
08-27-2012 1:41 PM
Hi Suhas,
If i remember correctly somewhere i had read that Field-Symbols are "dereferenced pointers" & reference variables are analogous "pointers".
You are spot on Suhas.
I think the issue stems from the ASSIGN statement.
I would think that the 'ASSIGN' statement is a 2 step process actually .
ASSIGN l_int to <fs>.
Step 1.->Retrieving the address of variable l_int into a reference variable (possibly in the Kernel).
Step 2.->The field symbol de references the address of the reference variable in step1.
This is where I believe the author drew his conclusion as 'Every field symbol is a dereferenced pointer'. - but as you know, a de referenced pointer is nothing but an alias for a variable/memory location .
To tell you the truth, I had a huge urge to type "The field symbol points to....", but somehow restrained myself .
Please let me know if I am missing anything here.
Thanks,
Venkat.
08-27-2012 7:30 AM
Hi,
Please refer the help documentation for field symbols.
http://help.sap.com/saphelp_bw30a/helpdata/en/fc/eb3860358411d1829f0000e829fbfe/content.htm
Thanks and regards,
Kartik
08-27-2012 7:46 AM
hi Sudheer,
Field Symbols
ABAP has featured field symbols as dereferenced pointers for some time now.
Field symbols allow you symbolic access to an existing data object. All
accesses that you make to the field symbol are made to the data object assigned
to it. Therefore, you can access only the content of the data object to which the
field symbol points. This technique is referred to as the value semantics of field
symbols.
Example:
DATA: date TYPE d VALUE ’20040101’, time TYPE t.
FIELD-SYMBOLS: <fs_date> TYPE d, <fs_time> TYPE t.
ASSIGN: date TO <fs_date>, time TO <fs_time>.
08-27-2012 8:13 AM
Hi,
one thing to point out is that field symbols are only bound to the fields during runtime of the program. Therefore syntax checks are not effective and can lead to runtime errors.
Hence it is advised not to use field symbols until you can achieve the same result using some other abap statement.
But even then if you are sure about the correctness of your code it can improve performance of your code.
for example
loop at it_table into wa_table operation time = 87,961
"work area operation
endloop.
loop at it_table assigning <fs_line> operation time = 2,877
<fs_line>-comp "direct field symbol operation
endloop.
The operation time stated above are from a program which used the above statements in it.
Thanks,
Karan
08-27-2012 8:39 AM
Thank you guys for helping me out to get the concept of Field-symbol. But still I'm not getting the difference between a pointer and a DE-referenced pointer....
08-27-2012 8:45 AM