SAP Tutorials Blog

 

Clearing Table

You can check whether an internal table is empty using logical expression:

... <itab> IS INITIAL ...

REFRESH <itab>.

Empties internal table.

CLEAR <itab>[].

Empties internal table without clearing the table work area.

CLEAR <itab>.

Empties internal table that has no table work area (header line).

Clears the table work area if the table has it.

FREE <itab>.

Emptie internal table and releases reserved memory without clearing the table work area.

Other perations With Internal Table

SORT <itab> [<order>] [AS TEXT]

[BY <f1> [<order>] [AS TEXT] ... <fn> [<order>] [AS TEXT]].

<order>: ASCENDING (default) or DESCENDING. Sorts by standard or self -defined (if BY defined) key. The system uses the options you specify before BY as a default for all fields specified behind BY. The options that you specify after individual fields overwrite for these fields the options specified before BY.

<f1> ... <fn> can be:

of any type, including type P, I, and F fields, or tables;

up to 250;

(<name>) instead of <f> (See also). The <name> contains the name of the field <f>. If <name> is empty at runtime, the system ignores it. If it contains an invalid component name, a runtime error occurs.;

table field name with Offset/Length specification;

Without the option AS TEXT, the system sorts character fields binarily and according to their platform-dependent internal coding. With the option AS TEXT, the system sorts character fields alphabetically according to the current text environment. By default, the text environment is set in the user's master record. As an exception, you can set the text environment with the SET LOCALE

LANGUAGE. The option AS TEXT frees you from converting a character field into a sortable format before sorting. Such a conversion is only necessary, if you want to

sort an internal table alphabetically first and search it binarily afterwards. The order of an internal table after alphabetical sorting differs from the order after binary sorting.

sort an internal table several times with alphabetical keys. In this case, the performance is better, because the conversion is processed only once;

create alphabetical indexes for database tables in your program.

AS TEXT before BY influences only the character fields in the sort key. If you specify AS TEXT after a field name, this field must be of type C. Sorting is not stable. This means that the old sequence of lines with the same sort key may not necessarily be retained. If there is not enough space for sorting in the main memory, the system writes data into a temporary external file. The name of this file is defined in the SAP profile parameter DIR_SORTTMP.


Serkan AKKAVAK

Computer Engineer BSc

SAP Department Manager

Contact : serkurumsal@yandex.com