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

Dynamic sort in ALV

Former Member
0 Likes
422

hi all,

HOw can we write the dynamic sort in ALV.

regards,

AJ

hi all,

HOw can we write the dynamic sort in ALV.

regards,

AJ

1 REPLY 1
Read only

former_member194669
Active Contributor
0 Likes
352

Hi,

Please find the sample code for dynamic sort in OO ALV


  perform built_sort_table.


form built_sort_table.
  data ls_sort_wa type lvc_s_sort.
  ls_sort_wa-spos = 1.
  ls_sort_wa-fieldname = 'MATNR'.    "<< here your pass fieldname to sort dynamically
  ls_sort_wa-up = selected.
  ls_sort_wa-subtot = ''.
  append ls_sort_wa to gt_sort.

  ls_sort_wa-spos = 2.
  ls_sort_wa-fieldname = 'STATUS'.  "<< here your pass fieldname to sort dynamically
  ls_sort_wa-up = selected.
  ls_sort_wa-subtot = ''.
  append ls_sort_wa to gt_sort.

endform.                               " BUILT_SORT_TABLE


    call method grid1->set_table_for_first_display
      exporting
        is_layout                     = gs_layout
        is_variant                    = gs_variant
        i_save                        = 'A'
        it_toolbar_excluding          = i_exclude[]
      changing
        it_outtab                     = i_output[]
        it_fieldcatalog               = i_fieldcat[]
        it_sort                       = gt_sort[]
      exceptions
        invalid_parameter_combination = 1
        program_error                 = 2
        too_many_lines                = 3
        others                        = 4.

aRs