2009 May 16 9:59 AM
hi,
i want to sort the int table with variable parameters, like VKBUR, BUDAT, VKORG, MATNR, etc.
for that ive created a char variable of 5 length (say CRIT) and assigned value based on selection criteria by the user.
Then, im using SORT ITAB BY CRIT. Its not getting sorted properly.
Any suggestions,
Regards,
Naveen
2009 May 16 12:24 PM
Field is provided dynamically so it must be enclosed in paranthesis.
SORT ITAB BY (CRIT). "depending on CRIT content i.e 'VKBUR' , 'BUDAT' it will sort using this field
Regards
Marcin
hi,
i want to sort the int table with variable parameters, like VKBUR, BUDAT, VKORG, MATNR, etc.
for that ive created a char variable of 5 length (say CRIT) and assigned value based on selection criteria by the user.
Then, im using SORT ITAB BY CRIT. Its not getting sorted properly.
Any suggestions,
Regards,
Naveen
2009 May 16 10:29 AM
please send the code with internal table structure, so ican send th correct code what to write..
Regards,
Prabhudas
2009 May 16 11:01 AM
Probably your assignement to variable could be wrong CRIT.
Check in debugger if the selected field is getting passed correctly.
Regards
Shital
2009 May 16 11:43 AM
Hi,
Char data type sort frist charectar wsie.
if u sort itab value -- 20
1
2
11
3
29.
After Sort Output:- 1
11
2
20
29
3
I sugest define CRIT - NUMC type.
2009 May 16 12:24 PM
Field is provided dynamically so it must be enclosed in paranthesis.
SORT ITAB BY (CRIT). "depending on CRIT content i.e 'VKBUR' , 'BUDAT' it will sort using this field
Regards
Marcin
2009 May 18 11:24 AM
You can easily achieve it by using filed symbols.
Assign the field (upon which you require sorting) to field symbol<Fs> and then sort the table with (<Fs>)reference.
Sample code is given below for your help.
DATA: BEGIN OF x1 OCCURS 0,
t1 TYPE string,
t2 TYPE string,
t3 TYPE string,
END OF x1.
FIELD-SYMBOLS: <fs> TYPE ANY.
x1-t1 = 'B'.
x1-t2 = 'D'.
x1-t3 = '9'.
APPEND x1.
x1-t1 = 'C'.
x1-t2 = 'X'.
x1-t3 = '4'.
APPEND x1.
x1-t1 = 'F'.
x1-t2 = 'Y'.
x1-t3 = '6'.
APPEND x1.
LOOP AT x1.
WRITE: / x1-t1, ' ', x1-t2, ' ', x1-t3.
ENDLOOP.
SKIP 2.
* Sort by field T1
ASSIGN 't1' TO <fs>.
SORT x1 BY (<fs>).
LOOP AT x1.
WRITE: / x1-t1, ' ', x1-t2, ' ', x1-t3.
ENDLOOP.
skip 2.
* Sort by field T3
ASSIGN 't3' TO <fs>.
SORT x1 BY (<fs>).
LOOP AT x1.
WRITE: / x1-t1, ' ', x1-t2, ' ', x1-t3.
ENDLOOP.
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |