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

SORTING ALV

Former Member
0 Likes
376

Hi all,

I need some immedaite help in ALV.I have 12 fields in my output Report. The report is working fine.The problem is with ALV.I have to SORT the ALV using two fields that are coming in my report. For eg. if Company code and Personnel Number(which are the Select Options in Selection Screen) are selected then Reported should be SORTED , first based on Com. Code and then based on PERNR. I think IT_SORT in SLIS_T_sortinfo_ALV will help but I do not know how to use it. And also Company Code and PERNR should be displayed only as Sub-Headings and not in ALV Report Columns.

And also if someone has an example ALV Report for ALV_Grid_Display or ALV_Block_Display, then that will be really helpful

Thanks in Advance

Sham

2 REPLIES 2
Read only

former_member184112
Active Contributor
0 Likes
351

Hi Sundar,

Please look at this Link..

https://www.sdn.sap.com/irj/sdn/forums

If this link helped u , pls give Reward Points in left hand side radio button.

Thanks and Regards,

Prabhakar Dharmala

Read only

0 Likes
351

Add this to your alv reporting

Add Default Sorting to ALVgrid report

In order to display an ALV report with specific columns already sorted by default you will need to build a

sort catalogue. This is fairly straight forward and is done in the following way:

Step 1. Add data declaration for sort catalogue

Step 2. Add code to build sort catalogue table

Step 3. Update 'REUSE_ALV_GRID_DISPLAY' FM call to include parameter 'it_sort'

  • ALV data declarations

data: it_sortcat type slis_sortinfo_alv occurs 1,

wa_sort like line of it_sortcat.

perform build_sortcat.

&----


*& Form build_sortcat

&----


  • Build Sort catalog

----


FORM build_sortcat .

wa_sort-spos = 1.

wa_sort-fieldname = 'EBELN'.

  • gd_sortcat-tabname

APPEND wa_sort TO it_sortcat.

wa_sort-spos = 2.

wa_sort-fieldname = 'EBELP'.

  • gd_sortcat-tabname

APPEND wa_sort TO it_sortcat.

ENDFORM. " build_sortcat

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

i_callback_program = gd_repid

i_callback_top_of_page = 'TOP-OF-PAGE'

is_layout = gd_layout

it_fieldcat = fieldcatalog[]

it_sort = it_sortcat

i_save = 'X'

tables

t_outtab = it_ekko

exceptions

program_error = 1

others = 2.

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

the data can be sorted in the code itself and not on the output using buttons...

u jus have to declare an internal table for sorting purpose and use the subroutine(sort_list in this example)...

data:IT_SORT TYPE SLIS_T_SORTINFO_ALV

FORM SORT_LIST .(subroutine)

CLEAR WA_SORT.

WA_SORT-FIELDNAME = 'AUART'.(population of sort internal table)

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.

********now passing the sort itab as parameter***********

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = G_REPID

IS_LAYOUT = WA_LAYOUT

IT_FIELDCAT = IT_FIELDTAB

IT_SORT = IT_SORT

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.

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

Use the statement as the one below:

SORT IT_HISTORY DESCENDING BY PLNDT.

This is sorting my output table(IT_HISTORY) descending by the field PLNDT without the use of any button .It comes as default when the user sees the ALV Display.

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

Thanks and Regards,

Prabhakar Dharmala