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 statement performance

sudha_naik
Product and Topic Expert
Product and Topic Expert
0 Likes
2,148

Hello

This sort statement is taking too much of time.

SORT MAKT_KEYTAB BY MATNR SPRAS.

Is there any option using which we can optimise this ?

Thanks

Sudha

8 REPLIES 8
Read only

Former Member
0 Likes
1,276

Hi,

send me your internal table strucutre.

Read only

Former Member
0 Likes
1,276

How did you define the table? If possible try sorted table.

Read only

sudha_naik
Product and Topic Expert
Product and Topic Expert
0 Likes
1,276

DATA: BEGIN OF MAKT_KEYTAB OCCURS 0,

MANDT LIKE SYST-MANDT,

MATNR LIKE MAKT-MATNR,

SPRAS LIKE MAKT-SPRAS,

END OF MAKT_KEYTAB.

Read only

0 Likes
1,276

DATA: BEGIN OF MAKT_KEYTAB OCCURS 0,

<b>MANDT LIKE SYST-MANDT,</b> ==> you don't need this line

MATNR LIKE MAKT-MATNR,

SPRAS LIKE MAKT-SPRAS,

END OF MAKT_KEYTAB.

Read only

Former Member
0 Likes
1,276

hI

MAKE IT AS binary SEARCH

SORT MAKT_KEYTAB BY MATNR SPRAS binary serach .

The binary search algorithm helps faster search of a value in an internal table. It is advisable to sort the internal table before doing a binary search. Binary search repeatedly divides the search interval in half. If the value to be searched is less than the item in the middle of the interval, the search is narrowed to the lower half, otherwise the search is narrowed to the upper half.

IF the int table is sorted by a key, then when BINARY SEARCH is added to a WITH KEY statement... the "read" to the int table is performed at a binary level for maximum performance.

if N is the number of entries in your itab, linear search is done in O(N) and binary search is done in O(logN).

use it if your itab is big, just don't forget to sort it if it's a standard table.

Read only

0 Likes
1,276

Don't think that any thing can be done to increase the performance of this SORT statement. Better try to split data in different tables.

Read only

Former Member
0 Likes
1,276

Hi,

It should work, may be because of huge amount of data it is taking lot of time.

try to move the MANDT field into last postion and then try.

reward if needful.

Thanks,

Sreeram.

Read only

Former Member
0 Likes
1,276

Hi,

You dont need to use MANDT and declaration there in internal table.

Use SORT statement including ASCENDING oor DESCENDING statement after that.

For e.g SORT INT_TAB ASCENDING BY MATNR SPRAS .

General Syntax :

SORT <itab> [ASCENDING|DESCENDING] [AS TEXT] [STABLE].

Thanks,

Sakthi C