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: 

Sort In alv After displaying the output

Former Member
0 Kudos
138

Hi all,

I need to sort the alv after displaying the output.The requirement is the user will select any column in the output and when he presses the sort(Custom Button) Button the entire output has to be displayed in the sort order of that column.Here I am using OOPs Concept.

Thank you.

Regards,CSR

5 REPLIES 5

hymavathi_oruganti
Active Contributor
0 Kudos
66

hi , there will be sorting buttons, sort assend and descend, just select a column and click on the button, it works.

Former Member
0 Kudos
66

Hello Ready,

This is the basic functionality of the ALV.

So u no need to write any code to do this.

Cheers,

Vasanth

0 Kudos
66

Hi ,

Thank you for your reply,

I know that functionality is availble but i want that one using the custom button when ever i select a particuler and click on that button the output has to be displayed in that order,

Thank you.

0 Kudos
66

hi reddy,

with the standard button, u can do it when ever u want.

if u want to code urself, make use of it_sort

datatype lvc_s_sort

0 Kudos
66

Hi ,

My problem solved using the methods set_sort_criteria and get_selected_columns.

Please find the related code.

any way thank you for all u r replys.

METHOD handle_user_command.

  • define local data

data:i_col type standard table of LVC_S_COL,

wa_col type LVC_S_COL,

wa_sort TYPE LVC_S_SORT.

CASE e_ucomm.

WHEN 'SORT_COL'.

REFRESH: mt_sort.

CALL METHOD sender->get_selected_columns

IMPORTING

ET_INDEX_COLUMNS = i_COL.

loop at i_col into wa_col .

wa_sort-spos = sy-tabix.

wa_sort-fieldname = wa_col-fieldname.

wa_sort-up = 'X'.

append wa_sort to mt_sort.

endloop.

CALL METHOD sender->set_sort_criteria

EXPORTING

it_sort = mt_sort

  • EXCEPTIONS

  • NO_FIELDCATALOG_AVAILABLE = 1

  • others = 2

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

*

CALL METHOD go_grid->set_table_for_first_display

EXPORTING

i_structure_name = 'VBAK'

is_layout = g_layout

CHANGING

it_outtab = g_outtab

it_sort = mt_sort

EXCEPTIONS

OTHERS = 4.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

WHEN OTHERS.

ENDCASE.

Thanks CSR.