2

I need an internal table with a hashed key, but multiple rows for each key. I think a deep table is the right solution for my problem, but how do I define it?

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
András
  • 1,326
  • 4
  • 16
  • 26

1 Answers1

6

You could use something like this:

TYPES: BEGIN OF ty_your_structure,
        field1 TYPE c LENGTH 10,
        field2 TYPE i,
       END OF ty_your_structure.
TYPES: BEGIN OF ty_your_table_structure,
        key TYPE string,
        rows TYPE STANDARD TABLE OF ty_your_structure WITH EMPTY KEY,
       END OF ty_your_table_structure.
TYPES tt_your_table TYPE HASHED TABLE OF ty_your_table_structure WITH UNIQUE KEY key.
DATA(lt_your_table) = VALUE tt_your_table( 
  ( key = 'TEST'  rows = VALUE #( ( field1 = 'X' field2 = 1 )
                                  ( field1 = 'Y' field2 = 2 ) ) )
  ( key = 'TES2T' rows = VALUE #( ( field1 = 'A' field2 = 1 )
                                  ( field1 = 'B' field2 = 2 ) ) )                                 
).
DATA(lt_rows) = VALUE #( lt_your_table[ KEY = 'TEST' ]-rows OPTIONAL ).
peterulb
  • 2,869
  • 13
  • 20