Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Method call in assign statement throws ERROR

Former Member
2,956

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

6 REPLIES 6
Read only

matt
Active Contributor
0 Likes
1,914

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!

Read only

benny_baby3
Discoverer
0 Likes
1,914

You are accessing the private method. Syntax error might be because of that?

Read only

matt
Active Contributor
1,914

No. Because when you move the method definition to public, you still get the error.

Read only

Sandra_Rossi
Active Contributor
0 Likes
1,914

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.

Read only

Former Member
0 Likes
1,914
  • This error occurrs on SAP NW 7.50. Also yes it was a mistake on my side that the get_data_ref is private it should be public of course.
Read only

DoanManhQuynh
Active Contributor
0 Likes
1,914

I think it because of method chaining have the same syntax ( method( )->...) so its not allowed to dereference there.