Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Issue on Sorting the itab

Former Member
0 Likes
621

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
597

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.

4 REPLIES 4
Read only

Former Member
0 Likes
597

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

Read only

0 Likes
597

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

Read only

0 Likes
597

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

Read only

Former Member
0 Likes
598

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.