简体   繁体   English

ABAP中的指针(如Java中的指针)

[英]Pointers in ABAP (like this in java)

Could anyone tell me how to define a pointer in ABAP OO? 谁能告诉我如何在ABAP OO中定义一个指针? In Java I have no problems with it, eg. 在Java中,我没有问题,例如。 this.name or this.SomeMethod() . this.namethis.SomeMethod()

Probably you are asking about so called self reference. 可能您正在询问所谓的自我参考。

In ABAP it is available by using keyword me . 在ABAP中,可以通过使用关键字me来使用。

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

ABAP uses field symbols. ABAP使用字段符号。 They are defined like: FIELD-SYMBOLS: , " TYPE any. TYPE file_table. If you want to dereference it, you need to do it using another field symbol like this: 它们的定义如下:FIELD-SYMBOLS:,“ TYPE any。TYPE file_table。如果要取消引用它,则需要使用另一个字段符号来做到这一点,如下所示:

ASSIGN str_mfrnr TO <str1>. 

This Stores the value of str_mfrnr into the field symbol. 这会将str_mfrnr的值存储到字段符号中。 If this is formatted as a work area like 'wa_itab-my_column', will now contain this string. 如果将其格式化为“ wa_itab-my_column”之类的工作区,则现在将包含此字符串。 Next, assign the location to another FS: 接下来,将位置分配给另一个FS:

ASSIGN (<str1>) TO <tmfrnr>.

now points to wa_itab-my_column. 现在指向wa_itab-my_column。 If you perform: 如果执行:

<tmfrnr> = some_value.

the location pointed to by now contains the value in some_value. 现在指向的位置包含some_value中的值。 ABAP pointers are more like C pointers, you have to know whether you are referenceing the value or the location. ABAP指针更像C指针,您必须知道要引用的是值还是位置。

Here's a small report I wrote a while ago to wrap my head around it. 这是我前一段时间写的一个小报告,以解决这个问题。 I think this is how it works: 我认为这是这样的:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM