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: 

sorted data on an alv grid

Former Member
0 Kudos

hi there,

i am displaying a data on the alv grid, how ever i want it in a sorted manner, where should i do that.

regards

8 REPLIES 8

Former Member
0 Kudos

Hi,

use the sort internal table IT_SORT to the function module parameter or to the method..

THanks,

naren

0 Kudos

can u expain ths in more detail

regards

Former Member
0 Kudos

Hi Chinmaya,

There are two options available..

1) You can do sorting in your ABAP code inself

SORT ITAB BY field1 field2.....

2) After displaying ALV grid there is standard functionality of sort given by SAP on application toolbar.

Regards,

Amey

0 Kudos

data:IT_SORT TYPE SLIS_T_SORTINFO_ALV,
************************************************88
FORM SORT_LIST .
CLEAR WA_SORT.
WA_SORT-FIELDNAME = 'AUART'.
WA_SORT-SPOS = '1'.
WA_SORT-UP = 'X'.
APPEND WA_SORT TO IT_SORT.
CLEAR WA_SORT.

WA_SORT-FIELDNAME = 'VBTYP'.
WA_SORT-SPOS = '2'.
WA_SORT-UP = 'X'.
APPEND WA_SORT TO IT_SORT.
CLEAR WA_SORT.

WA_SORT-FIELDNAME = 'WAERK'.
WA_SORT-SPOS = '3'.
WA_SORT-UP = 'X'.
WA_SORT-SUBTOT = 'X'.
APPEND WA_SORT TO IT_SORT.

*******************************************

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = G_REPID
IS_LAYOUT = WA_LAYOUT
IT_FIELDCAT = IT_FIELDTAB
<b>IT_SORT = IT_SORT</b>
TABLES
T_OUTTAB = IT_VBAK
* EXCEPTIONS
* PROGRAM_ERROR = 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.
ENDIF.

0 Kudos

i wan to do it in the abap code itself but where should that be done.

here is the code.

report ztst_chin_alv3.

----


tables : lfb1.

----


  • Declarations *

----


selection-screen begin of block a with frame title text-001.

select-options : bukrs for lfb1-bukrs.

select-options : lifnr for lfb1-lifnr.

selection-screen end of block a.

data: r_container type ref to cl_gui_custom_container.

data: r_grid type ref to cl_gui_alv_grid.

data: g_fieldcat type lvc_t_fcat.

data: w_fieldcat like line of g_fieldcat.

data: g_layout type lvc_s_layo.

data: ok_code like sy-ucomm.

data: gs_variant type disvariant.

data: t_selected type lvc_t_row.

data wa_selected like line of t_selected.

data: it_items like eban occurs 0.

data: begin of it_lfb1 occurs 0,

lifnr like lfb1-lifnr,

bukrs like lfb1-bukrs,

akont like lfb1-akont,

fdgrv like lfb1-fdgrv,

end of it_lfb1.

----


  • Initialization *

----


initialization.

at selection-screen.

ok_code = sy-ucomm.

case ok_code.

when 'BACK'.

leave program.

when 'CANCEL'.

leave program.

when 'EXIT'.

leave program.

when 'ONLI' or 'CRET'.

call screen 100.

when others.

endcase.

----


  • GetData *

----


module getdata output.

if sy-ucomm <> 'STOP'.

*refresh control container_1 from screen scr.

refresh it_lfb1.

clear bukrs.

clear lifnr.

select lifnr bukrs akont fdgrv

into corresponding fields of table it_lfb1

from lfb1

where

bukrs in bukrs

and lifnr in lifnr.

endif.

refresh bukrs.

refresh lifnr.

endmodule.

----


  • Create ALV *

----


module create_alv output.

gs_variant-report = sy-repid.

if r_container is initial.

create object r_container

exporting container_name = 'CONTAINER_1'.

create object r_grid

exporting i_parent = r_container.

endif.

*modify the headings in the field catalogue

call function 'LVC_FIELDCATALOG_MERGE'

exporting

i_structure_name = 'ztest_alv'

changing

ct_fieldcat = g_fieldcat[].

loop at g_fieldcat into w_fieldcat.

case w_fieldcat-fieldname.

when 'ZCURSTAT'.

w_fieldcat-scrtext_l = 'Prev.RelCode'.

w_fieldcat-scrtext_m = 'Prev.RelCode'.

w_fieldcat-scrtext_s = 'Prev.RelCode'.

w_fieldcat-reptext = 'Prev.RelCode'.

endcase.

modify g_fieldcat from w_fieldcat.

endloop.

call method r_grid->set_table_for_first_display

exporting i_structure_name = 'ztest_alv'

is_layout = g_layout

is_variant = gs_variant

i_save = 'A'

changing it_outtab = it_lfb1[]

it_fieldcatalog = g_fieldcat[].

*ELSE.

*

  • CALL METHOD r_grid->refresh_table_display

  • EXPORTING i_soft_refresh = ' '.

*

endmodule.

----


  • STATUS *

----


module status output.

set pf-status '0100'.

endmodule.

----


  • User Commands *

----


module user_command input.

ok_code = sy-ucomm.

case ok_code.

when 'BACK'.

call screen '1000'.

when 'CANCEL'.

leave program.

when 'EXIT'.

leave program.

endcase.

endmodule.

----


  • ALV Layout *

----


module layout output.

g_layout-zebra = 'X'.

g_layout-sel_mode = 'A'.

g_layout-grid_title = ''.

g_layout-detailtitl = ''.

endmodule.

----


  • Select Rows *

----


form get_selected_rows.

call method r_grid->get_selected_rows

importing et_index_rows = t_selected.

if t_selected is initial.

call function 'WS_MSG'

exporting

msg_type = 'E'

text = 'Select Line'

titl = 'Select Line'.

sy-ucomm = 'STOP'.

endif.

endform.

0 Kudos

Is there any other method by which i can have it sorted at the grid level and not internal table level. and i want it to be pre sorted.

Former Member
0 Kudos

How are displaying the ALV..are you using FM or OO..

Thanks,

Naren

Former Member
0 Kudos

Hi,

In the method SET_TABLE_FOR_FIRST_DISPLAY there is a parameter named IT_SORT..Pass the sort internal table T_SORT in this parameter..

DATA: T_SORT TYPE LVC_T_SORT.

DATA: S_SORT TYPE LVC_S_SORT.

S_SORT-SPOS = '1'.

S_SORT-FIELDNAME = 'MATNR'.

S_SORT-UP = 'X'.

APPEND S_SORT TO T_SORT.

CLEAR S_SORT..

Thanks

Naren