2009 Jan 27 5:43 PM
I want sort my table internal as number,
I have the field name with the content:+
I1
I10
I3
I4
I5
I6
I7
I8
I9
...
And when I used the next code:
SORT I_OBJECTS BY NAME AS TEXT.It is sort equal and I want obtain the next:
I1
I2
I3
I4
I5
I6
I7
I8
I9
I10
Can you help me, please?
Cordial greetings.
2009 Jan 27 5:58 PM
Hi
I think u need to insert a new field (a numeric field) in order to sort the table, the problem is NAME is char field so it'll be sorted as char and not as numeric.
So I think u need to create a numeric field where u insert the numeric part of field name.
Max
Edited by: max bianchi on Jan 27, 2009 6:58 PM
I want sort my table internal as number,
I have the field name with the content:+
I1
I10
I3
I4
I5
I6
I7
I8
I9
...
And when I used the next code:
SORT I_OBJECTS BY NAME AS TEXT.It is sort equal and I want obtain the next:
I1
I2
I3
I4
I5
I6
I7
I8
I9
I10
Can you help me, please?
Cordial greetings.
2009 Jan 27 5:53 PM
I've never done so, but in reading the help for SORT, it mentions the following. You might see if you can get this to work for you. You have to be on a later version of SAP, though.
Addition 5
... BY (otab)
Effect:
With the addition BY (otab), the table is not sorted according to the table key, but instead according to the component specified dynamically in the internal table otab (as of release 7.0). Each line of the table otab defined a component of the sort key. The priority of the sort is based on the order of the lines in otab. A maximum of 250 components can be specified. If the table otab is initial, the table is not sorted.
For otab, a standard table of the table type ABAP_SORTORDER_TAB from the ABAP Dictionary must be specified. The line type of this table is the Dictionary structure ABAP_SORTORDER with the following components:
*NAME of type SSTRING*
for specifying a component of the sort key. The component is entered in the form "comp_name[off(len)]", whereby "comp_name" must be the name of a component contained in itab in upper case to which an offset/length specification "off(len)" can be appended. "off" and "len" must be suitable numeric values.
DESCENDING of type CHAR of length 1 for specifying the
sort direction for the current component. If DESCENDING is initial, the sort is performed in ascending order. If DESCENDING has the value "X", the table is sorted in descending order.
ASTEXT of type CHAR of length 1
for textual sorting of the current component. If ASTEXT has the value "X", the sort is performed as with the AS TEXT addition. This is only possible for character-type components. If ASTEXT is initial, character-type components are sorted according to their binary representation.
2009 Jan 27 5:58 PM
Hi
I think u need to insert a new field (a numeric field) in order to sort the table, the problem is NAME is char field so it'll be sorted as char and not as numeric.
So I think u need to create a numeric field where u insert the numeric part of field name.
Max
Edited by: max bianchi on Jan 27, 2009 6:58 PM
2009 Jan 27 6:08 PM
tried to implement bubble sort. not sure if it will work but after some refinement it will work so just give it a try.
describe I_OBJECTS into v_lines.
loop at I_OBJECTS into wa.
v_idx = sy-tabix - 1.
small = wa-name+1(1).
do v_idx times.
read table i_objects into wa1 index v_idx.
var = wa1-name1+1(1).
if var < small.
small = wa1-name+1(1).
temp = wa1.
wa1 = wa.
wa = temp.
endif.
v_idx = v_idx + 1.
enddo.
endloop.
кu03B1ятu03B9к
2009 Jan 28 11:07 AM
Thank you for you attention, I solved the problem with two table internal that I used:
Post the code:
DATA: N LIKE SY-INDEX.
READ TABLE I_OBJECTS INDEX TC1-CURRENT_LINE.
IF SY-SUBRC EQ 0.
IF I_OBJECTS-NAME CP 'I*'.
N = I_OBJECTS-NAME+1(2).
READ TABLE OLD_SELECTIONS INDEX N.
MOVE OLD_SELECTIONS-FIELD TO NAME.
MOVE I_OBJECTS-OBLI TO OBLI.
MOVE I_OBJECTS-INVISIBLE TO INVISIBLE.
ELSE.
EXIT FROM STEP-LOOP.
ENDIF.
ELSE.
EXIT FROM STEP-LOOP.
ENDIF.
Cordial greetings.
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |