on 2022 Aug 10 2:29 PM
Hi Team, My internal table entries are like below
101
102
103
104
104
104
105
106
I want to sort the internal table like below
101
102
103
105
106
104
104
104
means repeated entries/duplicate (104) are should last in internal table.
Hi Sri ,
Try the below piece of code.
it_tab = VALUE #( ( num = 101 )
( num = 102 )
( num = 103 )
( num = 104 )
( num = 105 )
( num = 104 )
( num = 104 )
( num = 105 ) ) .
SORT it_tab BY num.
DATA(it_final) = it_tab .
LOOP AT it_tab ASSIGNING FIELD-SYMBOL(<fs_tab>) GROUP BY ( num = <fs_tab>-num size = GROUP SIZE )
ASSIGNING FIELD-SYMBOL(<num_group>).
CHECK <num_group>-size > 1.
it_members = VALUE #( FOR wa_num_grp IN GROUP <num_group> ( wa_num_grp ) ).
APPEND LINES OF it_members TO it_dup .
DELETE it_final WHERE num = it_members[ 1 ]-num .
CLEAR: it_members.
ENDLOOP.
APPEND LINES OF it_dup TO it_final.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Sri,
My first suggestion for your question would be:
SORT myinternaltable.
RETURN ADJACENT DUPLICATES FROM myinternaltable.
You can also go to SE30 and press F6. This will take you to the tips and tricks section. There, you will find some algorithms on how to efficiently deal with internal tables for loops and searching.
However, use two internal table is the best option. This definitely will not give any performance issue.
Kind Regards,
Andrew.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
69 | |
9 | |
8 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.