‎2019 Jul 17 1:23 PM
Hello everyone,
I have encountered a weird error while trying to "ASSIGN" the result of a method call (TYPE REF TO DATA) TO a field-symbol.
class lcl_test definition create public.
public section.
protected section.
private section.
methods get_data_ref
RETURNING VALUE(r_data) TYPE REF TO data.
endclass.
class lcl_test implementation.
method get_data_ref.
DATA lr_test_data TYPE REF TO data.
CREATE DATA lr_test_data TYPE TABLE OF sflight WITH EMPTY KEY.
r_data = lr_test_data.
endmethod.
endclass.
START-OF-SELECTION.
FIELD-SYMBOLS: <lta_data> TYPE ANY TABLE.
DATA(O_test) = new lcl_test( ).
ASSIGN o_test->get_data_ref( )->* TO <lta_data>.
I keep getting this error "The class "O_TEST->GET_DATA_REF( cannot be created as "FOR TESTING" since it is already referenced by non-test source code." which to me makes no sense in that context.
Shouldn't that be possible? I also tried it with a non generic returning value (char10).
It works in two steps. If you save the result of method "get_data_ref" in variable first and then pass that variable to the assign statement.
Kind regards,
Kai
‎2019 Jul 17 2:51 PM
Tried it on my system and got the same result. The error message is incorrect - it should say something about not being able to dereference a method call. You should report it on support.sap.com... having first shifted get_data_ref to the public section of course!
‎2019 Jul 17 3:09 PM
You are accessing the private method. Syntax error might be because of that?
‎2019 Jul 17 3:43 PM
No. Because when you move the method definition to public, you still get the error.
‎2019 Jul 17 3:35 PM
I get the syntax error message in 7.52 SP 1: "No method can be specified in the current position." (whatever GET_DATA_REF is private or public).
Anyway, returned values exist only for the duration of the current statement, so it's normal that it's not accepted for ASSIGN (at least in ABAP 7.52). There are a few other cases like that.
‎2019 Jul 17 4:56 PM
‎2019 Jul 18 1:44 AM
I think it because of method chaining have the same syntax ( method( )->...) so its not allowed to dereference there.