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

ABAP syntax error for combination of table expression + method chaining + itab is read-only

Sandra_Rossi
Active Contributor
4,635

Hello,

I have a test program below in my ABAP 7.52 system, having a syntax error in the second method, concerning the chaining of a method after a table expression on a read-only internal table.

Of course, I have the solution to avoid this syntax error, by splitting it into 2 lines, as I show in the first method.

But I don't understand why the compiler considers the table expression as being a "writing position" here, IMHO it should be considered a "reading position", but I can't find any explanation in the ABAP doc for table expressions.

Can you explain why + can you point to some reference in the ABAP documentation?

Thank you!

CLASS lcl_app DEFINITION.
  PUBLIC SECTION.
    TYPES ty_table_of_ixml TYPE STANDARD TABLE OF REF TO if_ixml WITH EMPTY KEY.
    METHODS test_has_valid_syntax IMPORTING table_of_ixml TYPE ty_table_of_ixml.
    METHODS test_has_syntax_error IMPORTING table_of_ixml TYPE ty_table_of_ixml.
ENDCLASS.
CLASS lcl_app IMPLEMENTATION.
  METHOD test_has_valid_syntax.
    data(ixml) = table_of_ixml[ 1 ].
    ixml->create_document( ).
  ENDMETHOD.
  METHOD test_has_syntax_error.
    table_of_ixml[ 1 ]->create_document( ). " !!! syntax error !!! The field "TABLE_OF_IXML" cannot be modified.
  ENDMETHOD.
ENDCLASS.
1 ACCEPTED SOLUTION
Read only

nomssi
Active Contributor
4,216

my guess: It is an evaluation error for the [ ]->method( ) expression, which is understood as [ ]-field_name

This works:

CAST if_ixml( table_of_ixml[ 1 ] )->create_document( ).

Hello,

I have a test program below in my ABAP 7.52 system, having a syntax error in the second method, concerning the chaining of a method after a table expression on a read-only internal table.

Of course, I have the solution to avoid this syntax error, by splitting it into 2 lines, as I show in the first method.

But I don't understand why the compiler considers the table expression as being a "writing position" here, IMHO it should be considered a "reading position", but I can't find any explanation in the ABAP doc for table expressions.

Can you explain why + can you point to some reference in the ABAP documentation?

Thank you!

CLASS lcl_app DEFINITION.
  PUBLIC SECTION.
    TYPES ty_table_of_ixml TYPE STANDARD TABLE OF REF TO if_ixml WITH EMPTY KEY.
    METHODS test_has_valid_syntax IMPORTING table_of_ixml TYPE ty_table_of_ixml.
    METHODS test_has_syntax_error IMPORTING table_of_ixml TYPE ty_table_of_ixml.
ENDCLASS.
CLASS lcl_app IMPLEMENTATION.
  METHOD test_has_valid_syntax.
    data(ixml) = table_of_ixml[ 1 ].
    ixml->create_document( ).
  ENDMETHOD.
  METHOD test_has_syntax_error.
    table_of_ixml[ 1 ]->create_document( ). " !!! syntax error !!! The field "TABLE_OF_IXML" cannot be modified.
  ENDMETHOD.
ENDCLASS.
16 REPLIES 16
Read only

rameez_khan
Active Participant
4,216

Dear,

If my understanding is correct then table expressions are used to return data and the data can be value, structure or object. Table expressions can be used in conditions to evaluate since they return data, so methods returning objects can be called directly from table expressions but methods which performs action cannot be called directly via table expressions..

You've got to use the first method.

Hope this helps.!!!

Cheers.

PS: Even I didn't found this in documentation.

Read only

0 Likes
4,216

EDIT: please ignore this comment, see next one.

No, it's allowed to use table expression + method chaining (abap >= 7.52), but with a writable internal table only. I have updated my question, by adding a demonstration in the first method, with a local variable. My question concerns the combination of the three : table expression + method chaining + read-only internal table (note: in my question, the parameter "table_of_ixml" is read-only because it's an Importing parameter).

Read only

0 Likes
4,216

Sorry, I understand what you say now.

This code has a valid syntax!! :

DATA(doc) = read_only_table_of_ixml[ 1 ]->create_document( ).

As I shown in my question, the next one isn't valid (syntax error "The field "TABLE_OF_IXML" cannot be modified"):

read_only_table_of_ixml[ 1 ]->create_document( ).

So, the question remains : why?

Read only

Sandra_Rossi
Active Contributor
0 Likes
4,216

Same code + example with an internal table being writable, and I also replaced the method called with the method activate which does not return anything to make sure the types of parameters have no impact on the syntax check:

CLASS lcl_app DEFINITION.
  PUBLIC SECTION.
    TYPES ty_table_of_ixml TYPE STANDARD TABLE OF REF TO if_ixml WITH EMPTY KEY.
    METHODS test_has_valid_syntax IMPORTING read_only_table_of_ixml TYPE ty_table_of_ixml.
    METHODS test_has_syntax_error IMPORTING read_only_table_of_ixml TYPE ty_table_of_ixml.
ENDCLASS.
CLASS lcl_app IMPLEMENTATION.
  METHOD test_has_valid_syntax.
    " Valid syntax for a read-only internal table, only if it's written in two parts 
    data(ixml) = read_only_table_of_ixml[ 1 ].
    ixml->activate( ).
    " Valid syntax if a writable internal table is used 
    data writable_table_of_ixml type ty_table_of_ixml.
    writable_table_of_ixml[ 1 ]->activate( ).
  ENDMETHOD.
  METHOD test_has_syntax_error.
    " !! syntax error !! The field "TABLE_OF_IXML" cannot be modified.
    read_only_table_of_ixml[ 1 ]->activate( ). 
  ENDMETHOD.
ENDCLASS.
Read only

fabianlupa
Contributor
0 Likes
4,216

Hi Sandra,

seems like a bug to me. The compiler should not evaluate the table expression method call to be a modifying operation to the read only table. It works if you change the method signature to pass by value by the way. (Maybe the newer method call syntax is implemented in a way that it expects an assignment on the right side of the statement and then it could be a modifying operation on the table?)

Would be interesting if the older CALL METHOD syntax could do it, but it of course does not support table expressions at all.

Read only

0 Likes
4,216

Maybe not a bug, but something not implemented yet, because the ABAP documentation often has "It is not yet possible to ..." (but couldn't find such a text corresponding to my question).

Read only

4,216

On a similar note: I am often missing this feature, where the solution also is to split things up into two statements:

lo_object->get_table_of_things( )[ 1 ]->do_stuff( ).
Read only

DoanManhQuynh
Active Contributor
0 Likes
4,216

so your read_only_table_of_ixml is importing parameter, it isnt supposed to be changed, is it? i think that syntax message not relevant to method chaning or table expression but the natural of import parameter. if its exporting or changing parameter i belive that your code will work.

Read only

0 Likes
4,216
But rameez.khan has shown that this code works, by adding an assignment :

DATA(doc)= read_only_table_of_ixml[1]->create_document().

So the reason is not because of the importing parameter.
Read only

0 Likes
4,216

no i dont think its mean that.

DATA(doc)= read_only_table_of_ixml[1]->create_document().

mean assign the import parameter to a help variable so its not mean that you change the import parameter. after that statement, your import table still not change and created document will assign to doc, right?

Read only

Sandra_Rossi
Active Contributor
4,216

As suggested by rameez.khan :

This code has a valid syntax!! :

DATA(doc)= read_only_table_of_ixml[1]->create_document().

As I shown in my question, the next one isn't valid (syntax error "The field "TABLE_OF_IXML" cannot be modified"):

read_only_table_of_ixml[1]->create_document().

So, the question remains : why?

Read only

nomssi
Active Contributor
4,217

my guess: It is an evaluation error for the [ ]->method( ) expression, which is understood as [ ]-field_name

This works:

CAST if_ixml( table_of_ixml[ 1 ] )->create_document( ).
Read only

Sandra_Rossi
Active Contributor
0 Likes
4,216

Thank you very much Jacques, nice finding !

Then maybe horst.keller could confirm.

Read only

nomssi
Active Contributor
0 Likes
4,216

I get Unexpected operator "->" on this: APPEND gt_ref[ key = 'my_key' ]-ref->* TO gt_data.

TYPES: BEGIN OF ts_data,
         key  TYPE char10,
         attribute TYPE i,
       END OF ts_data.
TYPES tt_data TYPE STANDARD TABLE OF ts_data.
  
TYPES: BEGIN OF ts_ref,
         key TYPE char10,
         ref TYPE REF TO ts_data,
       END OF ts_ref.
TYPES tt_ref TYPE STANDARD TABLE OF ts_ref.
 
DATA gt_data TYPE tt_data.
DATA gt_ref TYPE tt_ref.
  
APPEND gt_ref[ key = 'my_key' ]-ref->* TO gt_data.
Read only

Sandra_Rossi
Active Contributor
4,216

It works with ABAP 7.52 (before the APPEND, I had to add the 2 following lines:

gt_data = value #( ( key = 'a' ) ( key = 'b' ) ).
gt_ref = value #( ( key = 'my_key' ref = ref #( gt_data[ 1 ] ) ) ).
Read only

nomssi
Active Contributor
0 Likes
4,216

The syntax error occured on Netweaver 7.4, SP10 and SP18. It verify if was fixed on Netweaver 7.50 SP09