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: 

Is a hashed table sorted

Former Member
0 Kudos

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?

1 ACCEPTED SOLUTION

Jelena
Active Contributor

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

9 REPLIES 9

former_member186338
Active Contributor
0 Kudos

Yes, will be sorted.

0 Kudos

No. There is no defined sort order on a HASHED table. Almost by definition.

0 Kudos

My idea was that it can be sorted with a hash key... Just some misanderstanding from my side!

Sandra_Rossi
Active Contributor

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

Jelena
Active Contributor

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

Former Member
0 Kudos

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.

matt
Active Contributor

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.

Ryan-Crosby
Active Contributor

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

nomssi
Active Contributor

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.