2018 Nov 24 9:51 PM
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.
2018 Nov 26 1:16 PM
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.
2018 Nov 25 3:46 AM
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.
2018 Nov 25 8:30 AM
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).
2018 Nov 25 8:59 AM
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?
2018 Nov 25 8:40 AM
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.
2018 Nov 25 10:21 AM
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.
2018 Nov 25 11:56 AM
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).
2018 Nov 25 12:13 PM
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( ).
2018 Nov 26 2:51 AM
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.
2018 Nov 26 8:49 AM
DATA(doc)= read_only_table_of_ixml[1]->create_document().
So the reason is not because of the importing parameter.2018 Nov 27 12:24 AM
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?
2018 Nov 26 8:47 AM
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?
2018 Nov 26 1:16 PM
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( ).
2018 Nov 26 2:22 PM
Thank you very much Jacques, nice finding !
Then maybe horst.keller could confirm.
2018 Dec 06 6:36 AM
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.
2018 Dec 06 2:18 PM
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 ] ) ) ).
2018 Dec 06 7:04 PM
The syntax error occured on Netweaver 7.4, SP10 and SP18. It verify if was fixed on Netweaver 7.50 SP09
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |