Application Development and Automation 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: 
Read only

Sort without BY addition & Table Key

Former Member
0 Likes
1,430

Experts,

From SAP Help,


If no explicit sort key is entered using the BY addition, the internal table itab is sorted according to the table key.

I have code as below,


data: lt_vkonto type table of VKONT_KK. "Cont Acc No

"Fetch Cont Acc no against Contract

select vkonto from ever into table lt_vkonto where vertrag = wa_data-vertrag.

if sy-subrc eq 0.

sort lt_vkonto.

endif.

As seen above, I have sort statement without BY addition for internal table lt_vkonto which does not have a UNIQUE or NON UNIQUE key.

Will adding BY addition --> SORT lt_vkonto by vkonto imrpove the performance of sort statement.

Please share your valuable inputs.

BR,

Aspire

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
937

Hi

I don't know if you'll imporve the performace in your case, you should do some measurement, the problem should be the table key for a standard internal table (like yours) is the set of all CHAR fields.

In you situation you've only one fields, but probably if the table has several char fields the performance can be improved

Anyway I suppose it's always better to explicit an option else the system will have to deduct it by itself, so the system will do an additional step: in your case without BY, the system has to deduct the key to be used for the sorting.

Max

Experts,

From SAP Help,


If no explicit sort key is entered using the BY addition, the internal table itab is sorted according to the table key.

I have code as below,


data: lt_vkonto type table of VKONT_KK. "Cont Acc No

"Fetch Cont Acc no against Contract

select vkonto from ever into table lt_vkonto where vertrag = wa_data-vertrag.

if sy-subrc eq 0.

sort lt_vkonto.

endif.

As seen above, I have sort statement without BY addition for internal table lt_vkonto which does not have a UNIQUE or NON UNIQUE key.

Will adding BY addition --> SORT lt_vkonto by vkonto imrpove the performance of sort statement.

Please share your valuable inputs.

BR,

Aspire

1 REPLY 1
Read only

Former Member
0 Likes
938

Hi

I don't know if you'll imporve the performace in your case, you should do some measurement, the problem should be the table key for a standard internal table (like yours) is the set of all CHAR fields.

In you situation you've only one fields, but probably if the table has several char fields the performance can be improved

Anyway I suppose it's always better to explicit an option else the system will have to deduct it by itself, so the system will do an additional step: in your case without BY, the system has to deduct the key to be used for the sorting.

Max