Application Development 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: 

Sorting of Dyanmic internal table

Former Member
0 Kudos

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.

2 REPLIES 2

Former Member

naimesh_patel
Active Contributor
0 Kudos

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