ABAP中的字段符号和数据引用概念 [英] Field symbol and data reference concept in ABAP

查看:395
本文介绍了ABAP中的字段符号和数据引用概念的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我们将ABAP字段符号和数据引用与C中的指针进行比较,则会观察到:-

If we compare ABAP field symbols and data references with the pointer in C, we observe :-

在C中,我们声明一个变量 var,类型为整数,默认值为 5。

In C, say we declare a variable "var" type "integer" with default value "5".

变量 var将存储在内存中的某些位置,并说保存此变量的内存地址为 1000 。

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

现在,我们定义一个指针 ptr,并将该指针分配给变量。

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

ptr将为 1000, * ptr将为5。

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

让我们比较一下ABAP中的上述情况。

Lets compare the above situation in ABAP.

在这里,我们声明一个字段符号 FS,并将其分配给变量 var。

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

现在我的问题是 FS的含义是什么?我在互联网上进行了严格的搜索,但发现许多ABAP顾问认为FS拥有变量的地址,即1000。但这是错误的。在调试时,我发现fs仅占5。因此fs(在ABAP中)等效于* ptr(在C中)。如果我的理解是错误的,请纠正我。

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.

现在让我们声明一个数据引用 dref和另一个归档符号 fsym,并在创建数据引用后分配相同的到域符号。现在我们可以对该字段符号进行操作。因此,数据引用和字段符号之间的区别是:-

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 . 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.

推荐答案

字段符号很像一个指针,但您可以使用一个指针只能以取消引用的形式访问。换句话说,它会在内部保存分配给它的变量的内存地址,但不允许您看到内存地址,只能看到它指向的变量中存储的数据。可以证明这一点,因为如果您更改指向内部表行的字段符号的内容,则会看到更改将直接在行中进行。

The field-symbol is much like a pointer, but one that you can only access in a dereferenced form. In other words, it will hold, internally, the memory address of the variable that was assigned to it, but it will not allow you to see the memory address, only the data that is stored in the variable that it points to. This can be proved, because if you change the contents of a field-symbol that points to an internal table line, you'll see that the changes will be made directly in the line.

数据引用的行为就像一个简单的指针,只是您不能像C中那样增加或减少内存地址(ptr ++,ptr--等)。它与字段符号不同,因为您可以比较两个数据引用以检查它们是否指向内存中完全相同的位置。比较两个字段符号将是一个简单的值比较。另一个区别是,可以使用CREATE DATA命令通过创建数据引用来动态分配内存。字段符号只能分配给已经分配的变量。

A data reference acts like a simple pointer, except that you can't increment or decrement the memory address like in C (ptr++, ptr-- and such). It differs from a field-symbol because you can compare two data references to check if they point to the exact same spot in the memory. Comparing two field-symbols will be a simple value comparison. Another difference is that you can allocate memory dynamically by creating data references, with the CREATE DATA command. A field-symbol can only be assigned to an already allocated variable.

这篇关于ABAP中的字段符号和数据引用概念的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆