Register Login

Managing ABAP Sort - Physical sort (sort on disk), Index sort (Sort in memory)

Updated May 19, 2018

As of release 4.5A, the ABAP Sort has been completely re-implemented in R/3. The following describes the way the SORT works and any possible errors that can occur.                                                                  

Sorting in memory or on disk?                                                           

We assume a large internal table/extract that should be sorted using the ABAP SORT command.                                                                      

If the (width of the sort key) * (number of rows) > 12 MB, the disk-based sort is triggered.                                                           
Otherwise, the entire sort operation is performed in memory.                            


I  Physical sort (sort on disk)                                                         

The sort key * line count is larger than 12MB.

A sort file with the name S... is created in the directory defined in DIR_SORTTMP.

The table/extract to be sorted is then split into 8 MB chunks.These 8 MB are copied to an extra memory area and sorted using a quick sort algorithm. The result is written into the sort file.                                     

Unlike previous releases, an operating system sort is not used - the sort is performed entirely by R/3 kernel.                                                

This has two consequences:                                             

1.  Considerably less disk space is required for the sort operation because the various help files required for the operating system sort are no longer necessary. The only large sort file is built as   follows:
The first columns are filled with the sort key. The current row of the internal table to be sorted follows. Consequently, the size of the file is:(Sort key + line width * table entries. Note that the addition AS TEXT can increase the memory requirement of the sort by up to 8 times.                                                  


2.  The external SORT now required 8 MB main memory. This memory is ignored by the SAP Memory Management and allocated in heap memory. If insufficient memory is available, because, for example, batch jobs are currently using it all, the runtime error     EXSORT_NOT_ENOUGH_MEMORY occurs.                                   

The above transaction is repeated for each of the 8 MB sections. The result of this is one very large sort file that contains each of the sorted sections.

These individual results are then merged and put into the target table. The sort file is no longer required and is deleted.              

II Index sort (Sort in memory)                                  

The entire internal table/extract is sorted in memory in a single step. This only requires additional memory for the index. This is calculated as 4 bytes * line count of the extract/internal table.

Our Recommendation:

If you are using UNIX operating system, is advisable to create a separate file system of size 12 GB as

/usr/sap/sapsort

for ABAP sort. To use this file system for ABAP sort, you need to change the following parameters in SAP:

DIR_SORTTMP = /usr/sap/sapsort

The default directory is /usr/sap/<sid>/DVEBMGS00/data.

This helps to avoid load on the file system /usr/sap/<sid>. Though the sort file is automatically getting deleted by SAP system, it is important to ensure this file system not getting full at any point in time to get the better system performance.


×