‎2008 Sep 03 7:13 AM
Hi,
I have a requirment of sorting the internal table by one field.
for example zobject having the value of TE,RM,WP,RC,QM,SM,PE ........etc like that.
but i want to sort the object in the below order only(based on the value of the particular field),
RC,PE,TM,WP,SM,RM.......etc like that.
so how to sort this as per my requirment,if any one have a idea please share with me.
SORT gt_itab BY zobject .
Thanks,
With Regards,
Deesanth
‎2008 Sep 03 8:49 AM
Hi,
assume that your table(itab) is full of data.
Please do such a thing,
create another internal table(itab2) as of same type with your itab including one more field, a field just one char length, assume it is sortfield.
Do this:
loop at itab.
" RC,PE,TM,WP,SM,RM.......
if itab-zobject eq 'RC'.
itab2-sortfield = 'A'.
elseif itab-zobject eq 'PE'.
itab2-sortfield = 'B'.
....go on like this.
append itab to itab2.
endif.
endloop.sort itab2 by sortfield.Of course your main table is now itab2, display it.
Afterwards sort itab2 as above, if you do not want to display sortfield, you can do it through setting fieldcat properties.
This will sort your problem.
deniz.
‎2008 Sep 03 7:46 AM
what do u mean by object. An internal table can be sorted if u give the name of the fields it contains.
Ex: itab contains field1,field2,field3
so - sort itab by field1 field2.
this means it will be sorted first by field1 and second priority by field 2
Regards
Varun
‎2008 Sep 03 7:55 AM
Hi,
I am expecting the output of the filed object having many values,and that values should be display based on my sorting conditions,i want to sort by the values1 of the field only and not by filed 1,field 2,field3.
hope you understand my requirments.
Thanks,
Deesanth
‎2008 Sep 03 8:09 AM
From what i get u are trying to sort internal table using an external object which according to me is not possible.
u can sort only through field contained in it.
if u want only to sort it on 1 field
sort itab by field1
Edited by: Varun Mathur on Sep 3, 2008 12:39 PM
‎2008 Sep 03 8:49 AM
Hi,
assume that your table(itab) is full of data.
Please do such a thing,
create another internal table(itab2) as of same type with your itab including one more field, a field just one char length, assume it is sortfield.
Do this:
loop at itab.
" RC,PE,TM,WP,SM,RM.......
if itab-zobject eq 'RC'.
itab2-sortfield = 'A'.
elseif itab-zobject eq 'PE'.
itab2-sortfield = 'B'.
....go on like this.
append itab to itab2.
endif.
endloop.sort itab2 by sortfield.Of course your main table is now itab2, display it.
Afterwards sort itab2 as above, if you do not want to display sortfield, you can do it through setting fieldcat properties.
This will sort your problem.
deniz.