ABAP中的指针(在java中像这样)

时间:2014-05-30 03:37:23

标签: pointers abap

有人能告诉我如何在ABAP OO中定义指针吗? 在Java中我没有问题,例如。 this.namethis.SomeMethod()

3 个答案:

答案 0 :(得分:2)

可能你问的是所谓的自我引用。

在ABAP中,可以使用关键字me

Java中的示例:this.someMethod();
ABAP中的示例:me->someMethod( ).

答案 1 :(得分:1)

ABAP使用字段符号。它们的定义如下: FIELD符号:                ,“TYPE any。                 TYPE file_table。 如果要取消引用它,则需要使用其他字段符号来执行此操作:

ASSIGN str_mfrnr TO <str1>. 

这将str_mfrnr的值存储到字段符号中。如果将其格式化为“wa_itab-my_column”之类的工作区,则现在将包含此字符串。 接下来,将位置分配给另一个FS:

ASSIGN (<str1>) TO <tmfrnr>.

现在指向wa_itab-my_column。如果你执行:

<tmfrnr> = some_value.

now指向的位置包含some_value中的值。 ABAP指针更像是C指针,你必须知道你是在引用值还是位置。

答案 2 :(得分:0)

这是我前一段时间写的一篇小报告。我认为这是它的工作原理:

REPORT  zpointers.

* Similar to C:
***************
*  int *pointer;
*  int value = 1.
*  pointer = &value
*  int deref = *pointer

*this is the variable
DATA int TYPE i VALUE 10.
*this is the pointer, or the reference to a memory address
DATA pointer_i TYPE REF TO i.
*this is the dereferenced value, or the var that points to the
*value stored in a particular memory address
FIELD-SYMBOLS <int> TYPE i.

*the memory address of variable 'int' is now assigned to
*variable 'pointer_i'.
GET REFERENCE OF int INTO pointer_i.

*you can access the pointer by dereferencing it to a field symbol.
ASSIGN pointer_i->* TO <int>.