2009 Mar 05 12:01 PM
Hi all,
how to sort two alv fields by comparing with the first field..
field1 field2
1 a
1 a
1 b
2 c
3 c
i want to dispaly the output like the below
field1 field2
1 a
b
2 c
3 c
when i try the below code
wa_sort-spos = 1.
wa_sort-fieldname = 'FIELD1'.
append wa_sort to it_sort.
clear wa_sort.
wa_sort-spos = 2.
wa_sort-fieldname = 'FIELD2'.
append wa_sort to it_sort.
clear wa_sort.
the output is coming like this
field1 field2
1 a
b
2 c
3 -->c is merging for both 2 and 3
pls let me know how to rectify this..
Hi all,
how to sort two alv fields by comparing with the first field..
field1 field2
1 a
1 a
1 b
2 c
3 c
i want to dispaly the output like the below
field1 field2
1 a
b
2 c
3 c
when i try the below code
wa_sort-spos = 1.
wa_sort-fieldname = 'FIELD1'.
append wa_sort to it_sort.
clear wa_sort.
wa_sort-spos = 2.
wa_sort-fieldname = 'FIELD2'.
append wa_sort to it_sort.
clear wa_sort.
the output is coming like this
field1 field2
1 a
b
2 c
3 -->c is merging for both 2 and 3
pls let me know how to rectify this..
2009 Mar 05 12:03 PM
Its simple
for field 1 and field 2
pass sort_up = 'X'.
hope it helps
bhanu
2009 Mar 05 12:07 PM
Hi,
Try this:-
*SORTING
DATA : it_sort TYPE slis_t_sortinfo_alv,
wa_sort TYPE slis_sortinfo_alv.
*&---------------------------------------------------------------------*
* SORT W.R.T. FIELD1
*&---------------------------------------------------------------------*
wa_sort-spos = 1.
wa_sort-fieldname = '<FIELD1>'.
wa_sort-tabname = 'ITAB'.
wa_sort-up = 'X'.
APPEND wa_sort TO it_sort.
CLEAR wa_sort.
"now pass this it_sort in REUSE_ALV_GRID_DISPLAY
Hope this helps you.
Regards,
Tarun
2009 Mar 05 12:15 PM
Hi,
Instead of declaring the field catalog for sorting you can simply sort your internal table as follows:
SORT <i_tab> BY <field1> ASCENDING <field2> ASCENDING.Regards.
Edited by: rajan roy on Mar 5, 2009 1:30 PM
2009 Mar 05 1:26 PM
Hi Mallika,
Before passing the table for display ,
DELETE adjacent duplicates from t_itab comparing all fields.
describe table t_itab lines w_lines.
loop at t_itab.
w_fld1 = t_itab-fld1.
w_idx = sy-tabix + 1.
do w_lines times.
read table t_itab index w_idx.
if t_itab-fld1 = w_fld1.
t_itab-fld1 = space.
endif.
add 1 to w_idx.
if w_idx = w_lines.
exit.
endif.
enddo.
endloop.
fs_fcat-fieldname = 'FLD1'.
append fs_fcat to t_fcat.
fs_fcat-fieldname = 'FLD2'.
append fs_fcat to t_fcat.
fs_sort-spos = 1.
fs_sort-fieldname = 'FLD1'.
fs_sort-UP = 'X'.
append fs_sort to t_sort.
Regards,
Mdi.Deeba
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |