-2

​I have a requirement to display in an ALV Grid, quantities based on month wise, but only show the month columns that have at least one non-zero value.

Now, the ALV shows like this:

matnr     0101    0102    0103  ...  0110    0111    0112
-----     ----    ----    ----       ----    ----    ----
0123         0       0       0          0     234     345
0124         0       0       0        458     234     345

but, it should display only:

matnr     0110    0111    0112
-----     ----    ----    ----
0123         0     234     345
0124       458     234     345

How to hide the month columns that have only zero values?

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
PrisZhora
  • 1
  • 1
  • Be careful to preview your posts before publishing, the "table" was rendered in one line instead of several lines and several columns, it made your question unclear. I have updated it for you. – Sandra Rossi Jun 03 '19 at 07:01
  • Question also asked on [SCN](https://answers.sap.com/questions/12701296/dynamic-alv-based-on-months.html), with currently one answer. – Sandra Rossi Jun 03 '19 at 07:33

1 Answers1

2

In the field catalog of the ALV, which defines the way the columns are rendered, you may hide a column by either setting one of two properties or methods:

  • if you use CL_GUI_ALV_GRID, REUSE_ALV_GRID_DISPLAY REUSE_ALV_LIST_DISPLAY, set NO_OUT to 'X' or TECH to 'X'.
  • if you use SALV, you have the class CL_SALV_COLUMN or its subclasses, which change these properties via the respective methods SET_VISIBLE or SET_TECHNICAL.

Both properties or methods hide the column, but the first one (NO_OUT, SET_VISIBLE) let the user the possibility to show the column via the layout options, while the second one (TECH, SET_TECHNICAL) hides the column definitely.

Of course, first you'll have to loop at the internal table and check the contents of each column. Because you say you have a "dynamic ALV", I guess you'll have to use 'ASSIGN COMPONENT' to access the values of each row.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48