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

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

问题描述

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

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

在 C 中,假设我们声明了一个变量var",类型为integer",默认值为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天全站免登陆