01-08-2019 10:32 AM
Hello,
I want to use the corresponding operator to fill one internal table from a part of another internal table, but I get an error that the generic type tty_struc1 can't be constructed?
Thanks
Daniel
Example:
TYPES BEGIN OF struc1.
TYPES col1 TYPE char1.
TYPES col2 TYPE char1.
TYPES END OF struc1.
TYPES BEGIN OF struc2.
TYPES col1 TYPE char1.
TYPES col3 TYPE char1.
TYPES END OF struc2.
TYPES tty_struc1 TYPE STANDARD TABLE OF struc1.
TYPES tty_struc2 TYPE STANDARD TABLE OF struc2.
DATA lt_table1 TYPE tty_struc1.
DATA lt_table2 TYPE tty_struc2.
lt_table1 = VALUE #( ( col1 = 'A' col2 = '1' )
( col1 = 'B' col2 = '2' )
( col1 = 'C' col2 = '3' ) ).
lt_table2 = CORRESPONDING #( VALUE tty_struc1( ( LINES OF lt_table1 FROM 1 TO 2 ) ) ).
01-08-2019 11:49 AM
Hi Daniel,
Please declare Key with TYPES
TYPES tty_struc1 TYPE STANDARD TABLE OF struc1 with empty key
01-08-2019 12:10 PM
Thanks Muthu, it works now, but I thought without "with default key" the key is set to default key implicitely? Why do I have to set it explicitely here?
01-08-2019 12:36 PM
I am not sure whether it will do implicitely, Incase better we can mention any KEY fields or simply use WITH EMPTY KEY
01-08-2019 2:44 PM
Hello all,
Without key definition it use "Not specified" definition, and that is a generic type definition.
You can check that in SE11.
Classes have same problem when using a type STANDARD TABLE OF without key defined when used in RETURNING parameter.
01-08-2019 2:51 PM
01-08-2019 4:15 PM
You must use a so-called "complete data type" (i.e. a type which is not generic)
Here your type is a table which doesn't have a key defined, so it's generic.
Note that data objects typed with a generic type will in fact be assigned a so-called "bound data type" which completes what is missing in the generic type (incomplete key, incomplete table type...)
01-08-2019 4:27 PM
Thanks all for your comments. I got it now. The problem is that the "DEFAULT KEY" seems to be set only implicitely, if you declare the table with "DATA ... TYPE STANDARD TABLE OF ..." (w/o table type). When you use a table type, you need to define a key for the table type as mentioned, otherwise you'll get a generic type.
So in my example the following code would work also:
...
DATA lt_table1 TYPE STANDARD TABLE OF struc1.
DATA lt_table2 TYPE tty_struc2.
lt_table1 = VALUE #( ( col1 = 'A' col2 = '1' )
( col1 = 'B' col2 = '2' )
( col1 = 'C' col2 = '3' ) ).
lt_table2 = CORRESPONDING #( VALUE tty_struc1( ( LINES OF lt_table1 FROM 1 TO 2 ) ) ).