Application Development 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: 

CORRESPONDING operator in combination with VALUE and "FROM ... TO ..."

DanielB
Explorer
0 Kudos

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

Muthuraja
Active Participant

Hi Daniel,

Please declare Key with TYPES

Types - Keys

TYPES tty_struc1 TYPE STANDARD TABLE OF struc1 with empty key

DanielB
Explorer
0 Kudos

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?

Muthuraja
Active Participant
0 Kudos

I am not sure whether it will do implicitely, Incase better we can mention any KEY fields or simply use WITH EMPTY KEY

thalesvb
Active Contributor

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.

Muthuraja
Active Participant
0 Kudos

Hi Thales Batista

Thanks for your reply

Sandra_Rossi
Active Contributor

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

DanielB
Explorer

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