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 in ALV

Former Member
0 Likes
547

Hi

i have created an alv and i have written a code to get the invoice type, invoice date and material group.but the problem i face is that when i try to sort out by material group, i was unable to do so.the following is the code.

LOOP AT ITAB.

SELECT VBRKFKDAT VBRKFKART VBRP~MATKL INTO CORRESPONDING FIELDS OF ITAB

FROM VBRK

INNER JOIN VBRP

ON VBRKVBELN = VBRPVBELN

WHERE VBELN = ITAB-RDOC AND

VBRK~FKART IN FKART AND

VBRP~MATKL IN MATKL.

MODIFY ITAB.

ENDLOOP.

help me in sorting it.

4 REPLIES 4
Read only

Former Member
0 Likes
501

there is a table in the REUSE_ALV_GRID_DISPLAY

IT_SORT.

use this to specify which field u want to use for sorting and in which sequence.

reward if helpful.

Read only

Former Member
0 Likes
501

u can sort the internal table before calling the ALV funcation module depending on which fields. add the below code just after endloop.

sort ITAB by field1....

Read only

0 Likes
501

HI,

For sorting use the sort table for ALV function module :

for example:

After fetching the data into final table , fill the sort table and pass:

example code:

SORT T_FINAL BY VKORG KUNRG KUNAG.

RS_SORT-SPOS = 1.

RS_SORT-FIELDNAME = 'VKORG'.

RS_SORT-UP = 'X'.

RS_SORT-GROUP = '*'.

APPEND RS_SORT TO T_SORT.

RS_SORT-SPOS = 2.

RS_SORT-FIELDNAME = 'KUNRG'.

RS_SORT-UP = 'X'.

RS_SORT-GROUP = '*'.

APPEND RS_SORT TO T_SORT.

RS_SORT-SPOS = 3.

RS_SORT-FIELDNAME = 'KUNAG'.

RS_SORT-UP = 'X'.

RS_SORT-GROUP = '*'.

RS_SORT-SUBTOT = 'X'.

APPEND RS_SORT TO T_SORT.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_BACKGROUND_ID = 'SIWB_WALLPAPER'

I_CALLBACK_PROGRAM = SY-REPID

  • i_callback_user_command = 'USER_COMMAND'

IS_LAYOUT = S_LAYOUT

IT_FIELDCAT = T_FIELDCAT

IT_SORT = T_SORT[]

I_SAVE = V_SAVE

IS_VARIANT = S_VARIANT

IT_EVENTS = T_EVENTS

TABLES

T_OUTTAB = T_FINAL

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.

see in the above function module it_sort[].

regards,

sravanthi.

Read only

Former Member
0 Likes
501

hi,

Perhaps you can retreive the data in SELECT Query with ORDER BY DESC clause on Material Group.

This might solve Your problem.

Regards

Sumit Agarwal