2010 Feb 23 10:41 AM
Hi All,
i have to sort a set of records by one field.. this field could be blank and may have digits as well..
So i need to sort this internal table such that blank spaces have a precedence over alphabets and alphabets over digits.
How do i go about doing this..
Thanks in advance,
Herwin.
Hi,
Simply sort with your field ascending. Then the space will be the firs line.
Precedence is like SPACE then Numeric then Special Character then Alphabets
2010 Feb 23 10:49 AM
Hi,
Simply sort with your field ascending. Then the space will be the firs line.
Precedence is like SPACE then Numeric then Special Character then Alphabets
2010 Feb 23 10:53 AM
2010 Feb 23 11:02 AM
HI check this code it is working as u need.
TYPES: begin of t_c,
c type char1,
end of t_c.
data: t_tab type STANDARD TABLE OF t_c.
data w_c type t_c.
data:t_tab1 type STANDARD TABLE OF t_c.
w_c-c = space.
append w_c to t_tab.
w_c-c = '1'.
append w_c to t_tab.
w_c-c = 'a'.
append w_c to t_tab.
sort t_tab DESCENDING.
loop at t_tab into w_c where c is INITIAL.
append w_c to t_tab1.
endloop.
loop at t_tab into w_c where not c is initial .
append w_c to t_tab1.
endloop.
if sy-subrc = 0.
endif.
Check the entries in tab t_tab1 in debug. It is according to your requirement I hope.
Edited by: Anurag_n on Feb 23, 2010 12:03 PM
2010 Feb 23 11:12 AM
But this doesnt solve my problem its in descending order which shouldn't be the case.
2010 Feb 23 11:20 AM
Hi,
have you seen the entries in table t_itab1. If you check in debugger.. First line is blank second contain 'a' and third contain '1'
So i need to sort this internal table such that blank spaces have a precedence over alphabets and alphabets over digits.
2010 Feb 23 11:21 AM
Hello
Try this logic:
data: begin of itab occurs 0,
x(1),
y(1),
end of itab.
itab-y = '1'. append itab.
itab-y = ' '. append itab.
itab-y = 'A'. append itab.
itab-y = ' '. append itab.
itab-y = ' '. append itab.
itab-y = '3'. append itab.
itab-y = 'B'. append itab.
itab-y = ' '. append itab.
itab-y = '2'. append itab.
itab-y = 'C'. append itab.
itab-y = '8'. append itab.
itab-y = '1'. append itab.
itab-y = ' '. append itab.
loop at itab.
if itab-y eq space.
itab-x = '1'. modify itab.
else.
if itab-y CO '0123456789'.
itab-x = '3'. modify itab.
else.
itab-x = '2'. modify itab.
endif.
endif.
endloop.
sort itab.
| User | Count |
|---|---|
| 6 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |