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

wrong conversion error with sorted table?

EnnoWulff
Active Contributor
0 Likes
928

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

1 ACCEPTED SOLUTION
Read only

michael_piesche
Active Contributor
868

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.
3 REPLIES 3
Read only

michael_piesche
Active Contributor
869

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.
Read only

868

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.

Read only

868

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' ) ).