cancel
Showing results for 
Search instead for 
Did you mean: 

ALV doesn't sort as expected.

Former Member
0 Kudos

Hi,

I created sorting rules for two columns, document number and date. Each different date of a certain document constitutes a line in ALV. I used the following code to set the rules. However, the ALV doesn't sort as expected.

LOOP AT LT_FIELDS INTO LS_FIELDS.

     CASE LS_FIELDS-FIELDNAME.

       WHEN 'AUFNR'.

         LO_SORT_RULE ?= LS_FIELDS-R_FIELD->IF_SALV_WD_SORT~CREATE_SORT_RULE( SORT_POSITION = 1 ).

         LS_FIELDS-R_FIELD->IF_SALV_WD_SORT~SET_GROUPING_ALLOWED( ).

       WHEN 'ISSUE_DATE'.

         LO_SORT_RULE ?= LS_FIELDS-R_FIELD->IF_SALV_WD_SORT~CREATE_SORT_RULE( SORT_ORDER    = IF_SALV_WD_C_SORT=>SORT_ORDER_DESCENDING

                                                                              SORT_POSITION = 2 ).

         LS_FIELDS-R_FIELD->IF_SALV_WD_SORT~SET_GROUPING_ALLOWED( ABAP_FALSE ).

       WHEN OTHERS.

     ENDCASE.

   ENDLOOP.


The result is

Header 1Header 2
00120140101
00320140103
00620140104
002
004
005


But I expect the ALV to be sorted as follows

Header 1Header 2
00120140101
002
00320140103
004
005
00620140104


Accepted Solutions (0)

Answers (1)

Answers (1)

ramakrishnappa
Active Contributor
0 Kudos

Hi ts,

The above code used for sorting should work as you expected.But I suspect that the sort logic of field 'AUFNR'  is not executing / not reaching. Check the column name of HEADER1 column. It might be something else.

To make sure: check in debugging that the logic of AUFNR field gets reached.

Hope this helps you.

Regards,

Rama

Former Member
0 Kudos

Hi Rama,

Thank you for your reply. Rules for both columns are reached.

Best regards,

ts

ramakrishnappa
Active Contributor
0 Kudos

Hi ts,

As per your output table data, I can see that the date column also not sorted either.

Please share the snap shot of output table to have a better clarity.

Regards,

Rama