ABAP的指针问题,诚求解答
我定义了一个stack类,如下:CLASSstackDEFINITION.publicsection.~~~PRIVATESECTION.DATAgv_stacktbLI...
我定义了一个stack类,如下:
CLASS stack DEFINITION.
public section.
~ ~ ~
PRIVATE SECTION.
DATA gv_stacktb LIKE STANDARD TABLE OF t_point.
DATA gs_stack LIKE t_point.
DATA gv_dref_stack TYPE REF TO DATA.
DATA gv_dref_stack2 TYPE REF TO DATA.
DATA size TYPE i.
CLASS stack IMPLEMENTATION.
METHOD push.
CLEAR:gs_stack.
IF size < stack_maxsize.
FIELD-SYMBOLS:<fs_push_test> TYPE ANY.
ASSIGN i_pushtb->* TO <fs_push_test>.
GET REFERENCE OF <fs_push_test> INTO gv_dref_stack.
DATA i_test TYPE i.
i_test = 10086.
GET REFERENCE OF i_test INTO gv_dref_stack2.
IF sy-subrc EQ 0.
size = size + 1.
ENDIF.
ENDIF.
ENDMETHOD. "push
METHOD pop.
IF size > 0.
CLEAR:gs_stack.
IF sy-subrc EQ 0.
FIELD-SYMBOLS:<fs_pop_test> TYPE ANY.
ASSIGN gv_dref_stack->* TO <fs_pop_test>.
GET REFERENCE OF <fs_pop_test> INTO e_poptb.
IF sy-subrc EQ 0.
size = size - 1.
ENDIF.
ENDIF.
ENDIF.
ENDMETHOD. "pop
这个类的目的本身是为了实现栈的数据模型,并且我希望可以保存到任何数据类型(包括内表等)。
现在问题来了:
我在PBO中调用push以后,如果在同一PBO种立刻再调用pop,那么无论是size,gv_dref_stack,还是gv_dref_stack2,都能够如愿正常的保存数据下来。但是如果是PAI以后再执行PBO,当执行到pop(不会执行push),此时再调用,发现size是正常+1了,但是gv_dref_stack2和gv_dref_stack都变成空的了,虽然数据类型都还是正常的,比如gv_dref_stack2还是int,gv_dref_stack还是我push进去的那种内表类型,但是值都是空的了。
我创建对象只创建了一次
MODULE con_init OUTPUT.
IF g_docking IS INITIAL.
DATA undo_stack TYPE REF TO stack.
CREATE OBJECT undo_stack.
ENDIF.所以不存在对象创建造成值空的原因。 展开
CLASS stack DEFINITION.
public section.
~ ~ ~
PRIVATE SECTION.
DATA gv_stacktb LIKE STANDARD TABLE OF t_point.
DATA gs_stack LIKE t_point.
DATA gv_dref_stack TYPE REF TO DATA.
DATA gv_dref_stack2 TYPE REF TO DATA.
DATA size TYPE i.
CLASS stack IMPLEMENTATION.
METHOD push.
CLEAR:gs_stack.
IF size < stack_maxsize.
FIELD-SYMBOLS:<fs_push_test> TYPE ANY.
ASSIGN i_pushtb->* TO <fs_push_test>.
GET REFERENCE OF <fs_push_test> INTO gv_dref_stack.
DATA i_test TYPE i.
i_test = 10086.
GET REFERENCE OF i_test INTO gv_dref_stack2.
IF sy-subrc EQ 0.
size = size + 1.
ENDIF.
ENDIF.
ENDMETHOD. "push
METHOD pop.
IF size > 0.
CLEAR:gs_stack.
IF sy-subrc EQ 0.
FIELD-SYMBOLS:<fs_pop_test> TYPE ANY.
ASSIGN gv_dref_stack->* TO <fs_pop_test>.
GET REFERENCE OF <fs_pop_test> INTO e_poptb.
IF sy-subrc EQ 0.
size = size - 1.
ENDIF.
ENDIF.
ENDIF.
ENDMETHOD. "pop
这个类的目的本身是为了实现栈的数据模型,并且我希望可以保存到任何数据类型(包括内表等)。
现在问题来了:
我在PBO中调用push以后,如果在同一PBO种立刻再调用pop,那么无论是size,gv_dref_stack,还是gv_dref_stack2,都能够如愿正常的保存数据下来。但是如果是PAI以后再执行PBO,当执行到pop(不会执行push),此时再调用,发现size是正常+1了,但是gv_dref_stack2和gv_dref_stack都变成空的了,虽然数据类型都还是正常的,比如gv_dref_stack2还是int,gv_dref_stack还是我push进去的那种内表类型,但是值都是空的了。
我创建对象只创建了一次
MODULE con_init OUTPUT.
IF g_docking IS INITIAL.
DATA undo_stack TYPE REF TO stack.
CREATE OBJECT undo_stack.
ENDIF.所以不存在对象创建造成值空的原因。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询