我得到ThisIsNotAObjectReference语法消息时,试图处理一个完全类型的数据引用表达式,像这样:
method getDataReference.
rr_value = ref #( varStructure ).
endmethod.
data(lr_value) = object->getDataReference( )->structureComponent.
我理解的语法是相同的检索对象引用,但如何处理表达式中的完全类型的数据引用?
不能将方法调用与引用组件访问链接起来。你应该像这样使用辅助变量:
CLASS lcl_class DEFINITION.
PUBLIC SECTION.
METHODS: getdatareference RETURNING VALUE(rr_value) TYPE REF TO mara.
ENDCLASS.
CLASS lcl_class IMPLEMENTATION.
METHOD getdatareference.
DATA: ls_mara TYPE mara.
rr_value = REF #( ls_mara ).
SELECT SINGLE * FROM mara INTO rr_value->*.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
DATA(lcl) = NEW lcl_class( ).
DATA(lv_mara) = lcl->getdatareference( ).
DATA(l_matnr) = lv_mara->matnr.
我有点猜测你在这里想要实现什么,但据我所知,在你可以访问它们的内容之前,你需要取消引用数据引用。下面的代码扩展了上面发布的代码。
report ztest.
class lcl_test definition.
public section.
methods getDataReference
returning value(rr_value) type ref to tadir.
private section.
data varStructure type tadir.
endclass.
class lcl_test implementation.
method getDataReference.
varstructure-author = sy-uname.
rr_value = ref #( varStructure ).
endmethod.
endclass.
start-of-selection.
data(object) = new lcl_test( ).
data(lr_value) = object->getDataReference( ).
field-symbols <structure> type tadir.
assign lr_value->* to <structure>. " This is the dereferencing step
write / <structure>-author.