‎2020 Aug 24 2:38 PM
Hello!
I have the following issue:
This one works:
DATA ids TYPE TABLE OF char10.
ids = VALUE #( ( 'ONE' ) ( 'TWO' ) ( 'THREE' ) ( 'FOUR' ) ).
This one does'nt:
DATA ids TYPE SORTED TABLE OF char10 WITH UNIQUE KEY table_line.
ids = VALUE #( ( 'ONE' ) ( 'TWO' ) ( 'THREE' ) ( 'FOUR' ) ).
Error message in editor: "'ONE'" and the row type of "IDS" are incompatible.
"Solution": trailing spaces
ids = VALUE #(
( 'ONE ' )
( 'TWO ' )
( 'THREE ' )
( 'FOUR ' ) ).
SAP_BASIS: 754
SAP_ABA: 75E
Any ideas?
Thanks,
~Enno
‎2020 Aug 24 3:21 PM
I guess there is no other solution when using sorted tables with a key that is character. So it is not a bug with sorted/hashed tables, but a feature of standard tables.
This comes from the ABAP documentation:
- https://help.sap.com/doc/abapdocu_754_index_htm/7.54/en-US/abenvalue_constructor_params_itab.htm
" The constructed rows must meet the requirements of the statement INSERT for inserting work areas using table keys and therefore be compatible with the row type. There is one exception to this: When constructing a standard table, where the rows are only appended, the value can be shorter than the row length (for row types c and x), in which case it is padded on the right with blanks or hexadecimal 0.
‎2020 Aug 24 3:21 PM
I guess there is no other solution when using sorted tables with a key that is character. So it is not a bug with sorted/hashed tables, but a feature of standard tables.
This comes from the ABAP documentation:
- https://help.sap.com/doc/abapdocu_754_index_htm/7.54/en-US/abenvalue_constructor_params_itab.htm
" The constructed rows must meet the requirements of the statement INSERT for inserting work areas using table keys and therefore be compatible with the row type. There is one exception to this: When constructing a standard table, where the rows are only appended, the value can be shorter than the row length (for row types c and x), in which case it is padded on the right with blanks or hexadecimal 0.
‎2020 Aug 24 3:43 PM
Thanks, michael.piesche !
That seems to be the solution. It's so common that ABAP accepts "char-like" values that I never thought there would be stronger checks.
‎2020 Aug 24 3:59 PM
Enno Wulff, just as a side note:
It 'works' when the table has a structure and you have to address the field by its attribute name.
TYPES: BEGIN OF type,
key TYPE char10,
END OF type.
DATA ids TYPE SORTED TABLE OF type WITH UNIQUE KEY key.
ids = VALUE #( ( key = 'ONE' ) ( key = 'TWO' ) ( key = 'THREE' ) ( key = 'FOUR' ) ).