10-06-2008 10:14 PM
Hi Gurus,
I am having a dynamic internal table (it_mat) having fields matnr uname field1,field2,field3 and field4.
the field is upto fieldN.
I want my table to sorted by this manner
Sort it_mat by field4 field3 field2 field1.
Sort it_mat by fieldN field(N-1)...field1.
Please help me in to get this in dynamic manner.
10-06-2008 10:20 PM
10-06-2008 10:30 PM
You can try something like this:
types : begin of ty_comps.
include type abap_compdescr.
types: srl type i.
types : end of ty_comps .
data: lt_comps type standard table of ty_comps,
la_comps type ty_comps.
data: l_sort type standard table of char30 with header line.
loop at lt_tot_comp into la_comp. " LT_TOT_COMP contains all my components
move-corresponding la_comp to la_comps.
la_comps-srl = sy-tabix.
append la_comps to lt_comps.
clear la_comps.
endloop.
sort lt_comps by srl descending.
loop at lt_comps into la_comps.
l_sort = la_comps-name.
append l_sort.
endloop.
sort <f_tab> by (l_sort).
You can find the entire code which I have used to create a dynamic table at: [Dynamic Internal Table Creation|http://help-abap.blogspot.com/2008/09/dynamic-internal-table-creation.html]
Regards,
Naimesh Patel