Sie sind auf Seite 1von 19

BY:

RAJAT PURWAR

SORTING INTERNAL TABLES
AND
CONTROL LEVEL PROCESSING.

SORTING
INTERNAL TABLE CAN BE SORTED BY USING THESE
ADDITIONS :

1>.ASCENDING
2>.DESCENDING
3>.AS TEXT
4>.STABLE
SORTING -..ASCENDING



Effect
Sorts in ascending order. This is also the default if no sort order is
specified directly after SORT. For this reason, it is not necessary to
specify ASCENDING explicitly as the default sort order.

With the addition BY, you can also specify ASCENDING directly
after a sort field to define ascending order explicitly as the sort
sequence for this field.



EXAMPLES ARE :
1> SORT I_ZTABLE1 .
2.SORT I_ZTABLE1 BY NAME.
3>SORT I_ZTABLE1 ASCENDING BY NAME.


SORTING..DESCENDING
Effect
Sorts in descending order. If the addition comes right
after SORT, DESCENDING is taken as the default for all
fields of the sort key.

With the addition BY, you can also specify
DESCENDING directly after a sort field.


EXAMLES ARE :
1>SORT I_ZTABLE1 DESCENDING.
2>SORT I_ZRTABLE DESCENDING BY EMPID.
3>SORT I_ZTABLE1 DESCENDING BY NAME.
4>SORT I_ZTABLE1 DESCENDING BY NAME
COUNTRY SALARY.

OTHER EXAMPLES :
WE CAN ALSO USE THE ASCENDING AND
DESCENDING COMBINATION LIKE :
SORT <ITAB> [ASCENDENDING/DESCENDING]
BY <F1> [ASCENDING/DESCENDING]
<Fn> [ASCENDING/DESCENDING].




SORT I_ZTABELE1 DESCENDING BY NAME ASCENDING
SALARY DESCNDING
JOINING_DATE DESCENDING.
The table is now sorted by the specified
components <f
1 > ... <f n > instead of by the table key. The
number of sort fields is limited to
250. The sort order depends on the sequence of the fields <f i >.
The sort sequence specified before BY applies to all fields. The sort
sequence after a field applies only to that column of the table.
You can specify a sort field dynamically by specifying (<f>) instead
of <f i >. The contents of the field <f> determines the name of the
sort field. If <f> is empty when the statement is executed, the field
is ignored in the sort. If it contains an invalid component name, a
runtime error occurs.







SORTING..STABLE
The option
SORT <itab> ... STABLE.
allows you to perform a stable sort, that is, the
relative sequence of lines that are unchanged by the
sort is not changed. If you do not use the STABLE
option, the sort sequence is not preserved. If you
sort a table several times by the same key, the
sequence of the table entries will change in each
sort. However, a stable sort takes longer than an
unstable sort.

SORTING ALPHABETICALLY
As well as the ASCENDING or DESCENDING addition,
you can also specify that the entire sort or each sort field
should be alphabetical.
SORT <itab> ... AS TEXT ... .
This addition affects the sort method for strings.
Without the addition, strings are sorted according to
the sequence specified by the hardware platform.
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 master
record. However, you can also set it specifically using the
statement
SET LOCALE LANGUAGE

With the addition BY, you can also specify AS TEXT directly after
a sort field, provided it is of type C or W, or a structured type.
Otherwise, a runtime error occurs. In sort fields with a structured
type, AS TEXT only affects sub components with type C or W.


CONTROL LEVEL
PROCESSING
Control level processing is allowed within a LOOP over an
internal table. This means that you can divide sequences of
entries into groups based on the contents of certain fields.
Internal tables are divided into groups according to the
sequence of the fields in the line structure. The first column
defines the highest control level and so on. The control level
hierarchy must be known when you create the internal table.

The control levels are formed by sorting the internal
table in the sequence of its structure, that is, by the first
field first, then by the second field, and so on. Tables in
which the table key occurs at the start of the table are
particularly suitable for control level processing.


The AT statement introduces a statement block that you
end with the ENDAT statement.
AT <level>.
<statement block>
ENDAT.

The AT statements are :

1.AT FIRST/ENDAT.
First line of the internal table.
2. AT LAST/ENDAT.
Last line of the internal table.


3.AT NEW <f>/ENDAT.
Beginning of a group of lines with the same
contents in the field <f> and in the fields left of <f>.

4. AT END Of <f>/ENDAT.
End of a group of lines with the same contents in
the field <f> and in the fields left of <f>.

You can use control level statements to react to control
breaks in internal tables instead of programming them
yourself with logical expressions. Within the loop, you
must order the AT-ENDAT statement blocks according
to the hierarchy of the control levels. :
LOOP AT <itab>.
AT FIRST. ... ENDAT.
AT NEW <f1>. ...... ENDAT.
AT NEW <f
2
>. ...... ENDAT.
.......
<single line processing>
.......
AT END OF <f2>. ... ENDAT.
AT END OF <f1>. ... ENDAT.
AT LAST. .... ENDAT.
ENDLOOP.

If you are working with a work area <wa>, it does not contain
the current line in the AT... ENDAT statement block. All
character fields to the right of the current group key are filled
with asterisks (*). All other fields to the right of the current
group key contain their initial value.
Within an AT...ENDAT block, you can calculate the contents of
the numeric fields of the corresponding control level using the
SUM statement.
SUM.


You can only use this statement within a LOOP. If you use
SUM in an AT - ENDAT block, the system calculates
totals for the numeric fields of all lines in the current line
group and writes them to the corresponding fields in the
work area (see example in ). If you use the SUM
statement outside an AT - ENDAT block (single entry
processing), the system calculates totals for the numeric
fields of all lines of the internal table in each loop pass
and writes them to the corresponding fields of the work
area. It therefore only makes sense to use the SUM
statement in AT...ENDAT blocks.
If the table contains a nested table, you cannot use the
SUM statement. Neither can you use it if you are using a
field symbol instead of a work area in the LOOP
statement.

THANK YOU.

Das könnte Ihnen auch gefallen