Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Regarding Data Reference and Field Symbol

Former Member
0 Likes
2,599

Hi,

If we compare field symbol and data refernece with that of the pointer in C i conclud that :-

In C language, Say we declare a variable "var" type "Integer" with default value "5".

The variable "var" will be stored some where in the memory and say the memory address which holds this variable is "1000".

Now we define a pointer "ptr" and this pointer is assigned to our variable.

So, "&ptr" will be "1000" and " *ptr " will be 5.

Lets comapre the above situation in SAP ABAP.

Here we declare a Field symbol "FS" and assign that to the variable "var".

Now my question is what "FS" holds ? I have searched this rigorously in the internet but found out many ABAP consultants have the opinion that FS holds the address of the variable i.e. 1000. But that is wrong. While debugging i found out that fs holds only 5.

So fs (in ABAP) is equivalent to *ptr (in C). Please correct me if my understanding is wrong.

Now lets declare a data reference "dref" and another filed symbol "fsym" and after creating the data reference we assign the same to field symbol <fsym>. Now we can do operations on this field symbol. So the difference between data refernec and field symbol is :-

in case of field symbol first we will declare a variable and assign it to a field symbol.

in case of data reference first we craete a data reference and then assign that to field symbol.

Then what is the use of data reference. The same functionality we can achive through field symbol also.

Regards,

Debi

1 ACCEPTED SOLUTION
Read only

MarcinPciak
Active Contributor
1,625

Hi Debi,

I have seen you desperately trying to get the understanding of how field symbols and data reference of ABAP lies in relation to C pointers. I decided to give you some explanation in form of comparison both. I hope you will get the idea.

C

>1) integer var = 5 "-> our VAR

>2) integer *ptr "-> our pointer

>3) ptr = &var "-> set the pointer to point to VAR (get the address of VAR and store it in PTR)

>4) *ptr "-> value 5

>5) ptr "-> VAR address 1000

>5) &ptr "-> pointer address (some other i.e 1005)

ABAP

>1) data var type i value 5. "-> our VAR

>2) data ptr type ref to i. "-> our pointer

>3) get reference of var to ptr. "-> set the pointer to point to VAR (you can't show the address behind it)

>.4) ptr->* "-> value 5 (but can't be used directly in WRITE etc, must be first dereferenced via FIELD-SYMBOL)

> FIELD-SYBMOLS <fs>.

> ASSIGN ptr->* TO <FS>. "-> get the value PTR->* and let field-symbol to "point" to its value

> "now <FS> "-> value 5

>5) get reference of ptr to other_ptr. "-> pointer to pointer, never used in ABAP

So as you can see, the data references are something different then field-symbols . While the former is used to point to data, the latter is used to "point" to value behind it.

Regards

Marcin

Marcin - please do not use code tags to format text

Edited by: Rob Burbank on Sep 9, 2010 9:08 AM

Edited by: Thomas Zloch on Sep 9, 2010 3:48 PM

Hi Debi,

I have seen you desperately trying to get the understanding of how field symbols and data reference of ABAP lies in relation to C pointers. I decided to give you some explanation in form of comparison both. I hope you will get the idea.

C

>1) integer var = 5 "-> our VAR

>2) integer *ptr "-> our pointer

>3) ptr = &var "-> set the pointer to point to VAR (get the address of VAR and store it in PTR)

>4) *ptr "-> value 5

>5) ptr "-> VAR address 1000

>5) &ptr "-> pointer address (some other i.e 1005)

ABAP

>1) data var type i value 5. "-> our VAR

>2) data ptr type ref to i. "-> our pointer

>3) get reference of var to ptr. "-> set the pointer to point to VAR (you can't show the address behind it)

>.4) ptr->* "-> value 5 (but can't be used directly in WRITE etc, must be first dereferenced via FIELD-SYMBOL)

> FIELD-SYBMOLS <fs>.

> ASSIGN ptr->* TO <FS>. "-> get the value PTR->* and let field-symbol to "point" to its value

> "now <FS> "-> value 5

>5) get reference of ptr to other_ptr. "-> pointer to pointer, never used in ABAP

So as you can see, the data references are something different then field-symbols . While the former is used to point to data, the latter is used to "point" to value behind it.

Regards

Marcin

Marcin - please do not use code tags to format text

Edited by: Rob Burbank on Sep 9, 2010 9:08 AM

Edited by: Thomas Zloch on Sep 9, 2010 3:48 PM

8 REPLIES 8
Read only

ThomasZloch
Active Contributor
0 Likes
1,625

You know that your two previous questions have been locked. You can also assume that the third one will be detected.

So why are you asking again?

On the other hand, you are putting much effort into phrasing the question this time, so although I still not see a relevance for ABAP development in practice, I'll leave this thread open and see what happens.

Why do you need to know this? Is it for an exam or interview preparation?

Thomas

Read only

0 Likes
1,625

Hi Thomas,

Thank you... You did not close this thread.

I just want to answer your question - No, I am preparing neither for any interview nor for any exam. I searched many-a-times in SDN as well as in google but with no success.

I belive this thread will help many ABAP consultants.

Thanks again for your support.

Regards,

Debi

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,625

Please read SAP help documentation before posting.

link:[http://help.sap.com/saphelp_470/helpdata/en/fc/eb3860358411d1829f0000e829fbfe/content.htm].

Read only

MarcinPciak
Active Contributor
1,626

Hi Debi,

I have seen you desperately trying to get the understanding of how field symbols and data reference of ABAP lies in relation to C pointers. I decided to give you some explanation in form of comparison both. I hope you will get the idea.

C

>1) integer var = 5 "-> our VAR

>2) integer *ptr "-> our pointer

>3) ptr = &var "-> set the pointer to point to VAR (get the address of VAR and store it in PTR)

>4) *ptr "-> value 5

>5) ptr "-> VAR address 1000

>5) &ptr "-> pointer address (some other i.e 1005)

ABAP

>1) data var type i value 5. "-> our VAR

>2) data ptr type ref to i. "-> our pointer

>3) get reference of var to ptr. "-> set the pointer to point to VAR (you can't show the address behind it)

>.4) ptr->* "-> value 5 (but can't be used directly in WRITE etc, must be first dereferenced via FIELD-SYMBOL)

> FIELD-SYBMOLS <fs>.

> ASSIGN ptr->* TO <FS>. "-> get the value PTR->* and let field-symbol to "point" to its value

> "now <FS> "-> value 5

>5) get reference of ptr to other_ptr. "-> pointer to pointer, never used in ABAP

So as you can see, the data references are something different then field-symbols . While the former is used to point to data, the latter is used to "point" to value behind it.

Regards

Marcin

Marcin - please do not use code tags to format text

Edited by: Rob Burbank on Sep 9, 2010 9:08 AM

Edited by: Thomas Zloch on Sep 9, 2010 3:48 PM

Read only

0 Likes
1,625

Thanks Marcin,

You described the subject quite lucidly.

In below mentioned pseudo-code, i think you mean "ptr" instead of "var". (Point No.4 in ABAP)

4) var->* "-> value 5 (but can't be used directly in WRITE etc, must be first dereferenced via FIELD-SYMBOL)

FIELD-SYBMOLS <fs>.

ASSIGN var->* TO <FS>. "-> get the value VAR->* and let field-symbol to "point" to its value

Thank you,

Debi

Read only

0 Likes
1,625

Debi, you are absolutely right. My appoligies, nice you stay alert. I am correcting it right now.

Regards

Marcin

Strange, I can't edit my previous message. If anyone uses this as reference, please see Debi's corrections to my post.

Edited by: Marcin Pciak on Sep 9, 2010 2:28 PM

Read only

0 Likes
1,625

You cannot edit once somebody replied, I have done it now, please doublecheck.

Thomas

Read only

0 Likes
1,625

>

> You cannot edit once somebody replied, I have done it now, please doublecheck.

> Thomas

Heh, I am here for a while now and wasn't aware of that Will also keep in mind about quote tags for text. Thanks Thomas

One more spot to correct, please

5) get reference of var to other_ptr.

in place of VAR there should be PTR

Thank you once again

Marcin