0

Is it possible to automatically group rows on unsorted fields in an ALV? Suppose for instance that I have the following output:

1   T_PM1   0271    6025984     1271    602721
1   T_PM1   0271    6025984     1765    602721
1   T_PM1   0271    6025984     764     602721
1   T_PM1   0271    6025984     1242    602721
1   T_PM1   0271    6025984     1243    602721
1   T_PM1   0271    6025984     484     602721

Suppose I now sort on the first two columns and on the 5th. The first two columns will group to 1 and T_PM1 while the fifth will be sorted. However, the third, fourth and sixth columns all contain data that is derived from the first two columns and which is thus identical. How should I now force a grouping on these fields? (Note that I'm using the OO method of creating an ALV.)

The obvious solution would be to sort these columns as well but while I can't immediately think of a scenario where this would cause a bad sort, I am concerned that this makes my code less readable by inserting useless sorts and that these sorts will introduce unnecessary overhead by requiring an additional single pass through the data for every additional column to verify that it's already sorted.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Lilienthal
  • 4,327
  • 13
  • 52
  • 88
  • I don't understand your last paragraph - what "unnecessary sorts" are you talking about and what kind of "additional single pass" are you apparently assuming has to take place? – vwegert Dec 30 '13 at 10:51
  • As I see it, to group the the third, fourth and sixth column as well, I have to add their column names to the `SORT` statement, while they are already sorted, hence their mention is unnecessary. I would furthermore assume that for every one of these columns the remaining subset of unsorted records (in the example all of them) the sort logic will be iterated over to check if those fields are sorted. Of course I might be mistaken here, it could be that this logic is optimised automatically. – Lilienthal Dec 30 '13 at 12:21

1 Answers1

2

As far as I know, it is not possible to group values in the ALV Grid in unsorted columns. Be aware that sorting will be performed by the ALV grid, so adding the columns to your SORT statement should be completely unnecessary - in fact, the entire SORT statement should not be necessary.

The number of columns that are used to sort a table usually only have a small influence on the total sorting time - most of the time, you won't have to worry about this.

vwegert
  • 18,371
  • 3
  • 37
  • 55
  • As I suspected, I'll just add all the required sorts. As you say I mistakenly referred to the `SORT` statement while the actual approach I use is via `cl_salv_sorts` with corresponding statements `lo_sorts->add_sort( columnname = '####' ).`. Initial tests seem to confirm that any performance impact is negligible, certainly when compared to DB access times. – Lilienthal Dec 31 '13 at 07:48