Skip to Content
avatar image
Former Member

Is a hashed table sorted

If we do a select into an internal table which is of type 'hashed table', will the entries be sorted by the key you provided in the definition of the hashed table?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

6 Answers

  • Best Answer
    Oct 21, 2016 at 08:49 PM

    But why does it matter? Hashed tables meant to be accessed by key anyway. Also would be very easy to check in debugger, I guess. I would but I fail to see the importance here. :) Maybe I'm missing something...

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Dear Jelena

      At a customer we did a select into a hashed table with one key.
      We expected to see all the data in this hashed table in debugger but couldn't find the entry we were looking for because the data was not sorted. That's why I asked this question in order to find out if we made some kind of error.

      After some further discussions with colleagues we found out that a hashed table is not sorted.

  • Oct 24, 2016 at 11:44 AM

    There is no defined sort order on a HASHED table. You can sort a HASHED table and loop through it and get the records in order, but if you don't sort it, you absolutely cannot rely on any sort order.

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 24, 2016 at 01:08 PM

    No, hashed tables are not in any sorted order and aside from any specialized implementations they are not addressable by index. Here is the definition directly from the help that describes them in a brief statement.

    Regards,

    Ryan Crosby

    Add comment
    10|10000 characters needed characters exceeded

  • Nov 02, 2016 at 06:17 PM

    Note you can define secondary keys for internal table since Netweaver 7.02+, but you must also specify the key (k1in my example) while accessing the table entries say in a LOOP or a READ TABLE.

    DATA itab TYPE HASHED TABLE OF s1 WITH UNIQUE KEY b
    WITH UNIQUE SORTED KEY k1 COMPONENTS a c.
    Add comment
    10|10000 characters needed characters exceeded

  • Oct 21, 2016 at 04:11 PM

    EDIT: Agreed. a hashed table has NO sort order (Initial answer: Yes or No, it d├ępends from external factors not related to the information you posted. If you insert 2 lines chronologically in the reverse order of the key, and you do a simple LOOP AT without mentioning any key, then it will read chronologically and not based on the key.)

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 21, 2016 at 03:25 PM
    -4

    Yes, will be sorted.

    Add comment
    10|10000 characters needed characters exceeded