2007 Oct 08 9:09 AM
sort an internal table - of course, without using the sort verb.
Table has two fields:
Key1(4) TYPE C,
data(8) TYPE C.
sort an internal table - of course, without using the sort verb.
Table has two fields:
Key1(4) TYPE C,
data(8) TYPE C.
2007 Oct 08 9:11 AM
Hi Megha,
Declare the internal table as sorted table. see the syntax. then the table is automatically sort when you enter the entry.
Thanks,
Sunil
2007 Oct 08 9:21 AM
2007 Oct 08 9:23 AM
u must hav declared table as
data: it_tab type standard table of <>.
instead of dat use SORTED
data: it_tab type sorted table of <>.
Reward points if helpful
2007 Oct 08 9:32 AM
but i don't want to use 'SORT' word into my program then how can i do?
2007 Oct 08 9:32 AM
Hi Megha,
Try this
TYPES : BEGIN OF w_itab,
key1(4) TYPE c,
data(8) TYPE c,
END OF w_itab.
DATA: itab TYPE SORTED TABLE OF w_itab WITH HEADER LINE WITH UNIQUE KEY key1.
Regards,
Amit
2007 Oct 08 9:41 AM
Hi,
Check the below addition of APPEND verb.
APPEND [wa TO] itab SORTED BY f.
<b>Effect</b>
Inserts the new entry into table and re-sorts the table by the sub-field f in descending order. This only makes sense if the table was sorted beforehand. When the number of table entries reaches the INITIAL SIZE parameter value, the last entry is deleted if the value f of a new entry is greater (particularly suitable for ranked lists). You can only sort by one component, and may only use this variant with a STANDARD TABLE.
If you specify wa TO, the new line is taken from the contents of the explicitly specified work area wa. Otherwise, it comes from the header line of the internal table itab.
<b>Example</b>
TYPES: BEGIN OF COMPANIES_TYPE,
NAME(10), SALES TYPE I,
END OF COMPANIES_TYPE.
DATA COMPANIES TYPE STANDARD TABLE OF COMPANIES_TYPE
INITIAL SIZE 3,
WA_COMPANIES TYPE COMPANIES_TYPE.
WA_COMPANIES-NAME = 'big'.
WA_COMPANIES-SALES = 90.
APPEND WA_COMPANIES TO COMPANIES.
WA_COMPANIES-NAME = 'small'.
WA_COMPANIES-SALES = 10.
APPEND WA_COMPANIES TO COMPANIES.
WA_COMPANIES-NAME = 'too small'.
WA_COMPANIES-SALES = 5.
APPEND WA_COMPANIES TO COMPANIES.
WA_COMPANIES-NAME = 'middle'.
WA_COMPANIES-SALES = 50.
APPEND WA_COMPANIES TO COMPANIES SORTED BY SALES.
The table now has three (-> INITIAL SIZE 3) entries. The line with the contents 'too small' in the sub-field NAME is deleted from the table because the entry for 'middle' has a greater value in the component SALES. This entry now appears in the second table line (after 'big' and before 'small').
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |