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

ALV - Sort empty dates at bottom

Former Member
0 Likes
2,256

Hi,

I'm working with an ALV grid, specifically cl_salv_hierseq_table, and I have a column that shows date values.

Sorting must be enabled for the date column. However, an empty date will sort to the top of the list with an ascending sort, and to the bottom with a descending sort.

Is there a way to make ALV (or the SORT statement for an internal table) treat an empty date as a high value?

If not, I could set all empty date values to 12/31/9999, if I could find a way to make ALV suppress their display (i.e. if the date value for that row is 12/31/9999, show it as blank to the user). Can that be done?

Thanks.

1 ACCEPTED SOLUTION
Read only

former_member129652
Active Participant
0 Likes
1,454

Hi Eric,

  The SORT statement cannot move the empty dates to the end of the internal table. I will use the following approach.

  1. Disable the default sorting button of salv. 
  2. Create my own sort button with my own function code in the application toolbar.
  3. Implement the my sorting function and move the empty dates to the end of the internal table

Best regards

5 REPLIES 5
Read only

Puneet_Gupta
Contributor
0 Likes
1,454

Hi Eric,

I don't think this will be possible for the sort/alv. The sort works on the contents of the entire column. You could change the value from blank date to something higher like 12/31/9999 but you will not be able to suppress it by rows.

- Puneet

Read only

former_member129652
Active Participant
0 Likes
1,455

Hi Eric,

  The SORT statement cannot move the empty dates to the end of the internal table. I will use the following approach.

  1. Disable the default sorting button of salv. 
  2. Create my own sort button with my own function code in the application toolbar.
  3. Implement the my sorting function and move the empty dates to the end of the internal table

Best regards

Read only

0 Likes
1,454

Hi,

For SORT statement on internal table it can be done indirectly by creating another field & copy contents of  date field to be sorted, into this field ( with date as 31/12/9999 in case it is blank aspointed out by you  ), & sort the internal table on this new hidden column.

I hope this helps,

Regards

Raju Chitale

Read only

0 Likes
1,454

Michael,

Thanks for this idea. I'm sure it would work, but I'll use a simpler solution to get it done more quickly. Details in my response to Raju...

Read only

0 Likes
1,454

Raju,

I did this and it worked well.

I also called the set_technical method (with a value of true) on the column object, to make sure not only that this new column would not be visible on the report, but that it would also not be available for the user to choose in the "Change Layout" functionality.

Thanks!